guardrail icon indicating copy to clipboard operation
guardrail copied to clipboard

Missing type mapping for class io.swagger.v3.oas.models.media.Schema

Open KineticCookie opened this issue 2 years ago • 2 comments

Hi! I have a quite big OASv3 yaml file and was trying out guardrail to generate http4s server.

plugins.sbt
...
addSbtPlugin("dev.guardrail"   % "sbt-guardrail"      % "0.75.0")
build.sbt
...
Compile / guardrailTasks := List(
  ScalaServer(
    file(".") / "documentation" / "api" / "backend.yaml",
    framework = "http4s",
    pkg = "com.example.server"
  )
)

After running compile I get the following error:

WARNING: Missing type mapping for class io.swagger.v3.oas.models.media.Schema, please report this at https://github.com/guardrail-dev/guardrail/issues
Error:Missing type
[error] (Compile / guardrail) dev.guardrail.sbt.CodegenFailedException

which is quite confusing and it prevents me from troubleshooting.

And is there a way to enable more logs?

KineticCookie avatar Sep 22 '22 09:09 KineticCookie

Ok, I got the troublemaker

I got format: string instead of type: string in request schema.

        - in: path
          name: propertyName
          schema:
            format: string
          required: true

Fixing it solved the issue.

But I think errors should be more informative. Maybe point to a specific path where issue happened?

KineticCookie avatar Sep 22 '22 10:09 KineticCookie

Also discovered another error(?):

servers:
    - url: /api/1-dev/

fails with

Error:Failed to parse URL: endOfInput (unparsed: /datasets/) (.paths./datasets/)
[error] (Compile / guardrail) dev.guardrail.sbt.CodegenFailedException

/datasets/ -- the first api url in the spec

while

servers:
    - url: /api/1-dev

doesn't

KineticCookie avatar Sep 22 '22 10:09 KineticCookie

Also discovered another error(?):

servers:
    - url: /api/1-dev/

fails with

Error:Failed to parse URL: endOfInput (unparsed: /datasets/) (.paths./datasets/)
[error] (Compile / guardrail) dev.guardrail.sbt.CodegenFailedException

/datasets/ -- the first api url in the spec

while

servers:
    - url: /api/1-dev

doesn't

That was unexpected

blast-hardcheese avatar Sep 24 '22 00:09 blast-hardcheese

Ok, I got the troublemaker

I got format: string instead of type: string in request schema.

        - in: path
          name: propertyName
          schema:
            format: string
          required: true

Fixing it solved the issue.

But I think errors should be more informative. Maybe point to a specific path where issue happened?

Totally agree. I haven't had time to research this, but I'm actually really surprised that the error isn't more descriptive, this is the whole reason I wrote Tracker[?]

blast-hardcheese avatar Sep 24 '22 00:09 blast-hardcheese

OK, I found the issue with the error log, fix to go out with the next release. Having done the exact same thing, digging through extraordinarily large OpenAPI specs to find an error, I really apologize for that user experience.

Looking at the second issue with the path now.

blast-hardcheese avatar Sep 25 '22 19:09 blast-hardcheese

OK, split out #1594 and issued a patch for that one as well.

blast-hardcheese avatar Sep 25 '22 20:09 blast-hardcheese

Thank you for the report(s)!

blast-hardcheese avatar Sep 25 '22 20:09 blast-hardcheese

OK, "dev.guardrail" %% "guardrail-core" % "0.75.2" is being released right now. If you add that as a libraryDependency in your project/plugins.sbt then both of the reported issues here should no longer be an issue.

blast-hardcheese avatar Sep 27 '22 06:09 blast-hardcheese

Awesome, thank you! 👍

KineticCookie avatar Sep 28 '22 19:09 KineticCookie