guardrail-dev / guardrail-dev/guardrail

Duplicate responses fail compilation (http4s framework)

Open
#554 11 comments 0 reactions 0 assignees View on GitHub
bug core scala-http4s
Dominant language
Scala
Stars
541
Forks
138
PR merge metrics
No merged PRs in 30d

Description

Hi,
I'm working on a project with http4s and guardrail. When I generate both server and client code, I end up with duplicate response models in the same package, which of course fails compilation ("GetUserResponse is already defined as class GetUserResponse", "GetUserResponse is already defined as object GetUserResponse").

Here's an example of yaml:

```yaml
openapi: '3.0.2'
info:
title: User example
version: 1.0.0-SNAPSHOT

paths:
/user:
get:
x-scala-package: users
operationId: getUser
responses:
200:
description: 'OK'
content:
application/json:
schema:
$ref: '#/components/schemas/GetUserResponse'

components:
schemas:
GetUserResponse:
type: object
properties:
user:
$ref: '#/components/schemas/User'
User:
type: object
required:
- name
properties:
name:
type: string
```

Here's an excerpt of my `build.sbt`:

```scala
Compile / guardrailTasks := List(
ScalaServer((Compile / resourceDirectory).value / "api.yaml", pkg = "api.routes", framework = "http4s"),
ScalaClient((Compile / resourceDirectory).value / "api.yaml", pkg = "api.routes", framework = "http4s")
)
```

I could define different values of `pkg` for server and client and prevent the compilation error, but this would result in duplicate code being generated for the same API...

Is this a correct and known behavior?
Thank you in advance

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.