Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unknown type for the following structure (type: string, class: io.swagger.v3.oas.models.media.PasswordSchema) #255

Open
tomasherman opened this issue Apr 26, 2019 · 12 comments

Comments

Projects
None yet
4 participants
@tomasherman
Copy link
Contributor

commented Apr 26, 2019

Update This issue is tracking errors generated by following schemas:

swagger: "2.0"
info:
  title: Whatever
  version: 1.0.0
host: localhost:1234
schemes:
  - http
definitions:
  Foo:
    type: object
    properties:
      somePassword:
        type: string
        format: password
      someFile:
        type: file
      someBinary:
        type: string
        format: binary

They all generate errors similar to this one:

Error: Unknown type for the following structure (type: string, class: io.swagger.v3.oas.models.media.PasswordSchema):
  class PasswordSchema {
      class Schema {
      }
      type: string
      format: password
  }

Original issue:

Hi,

when using follwing definition:

{"password":{"format":"password","type":"string"}}

I get the following error:

Error: Unknown type for the following structure (type: string, class: io.swagger.v3.oas.models.media.PasswordSchema):
  class PasswordSchema {
      class Schema {
      }
      type: string
      format: password
  }

Any idea what to do about it? I suspect it's a format that has been removed in swagger v3 or something like that

@tomasherman

This comment has been minimized.

Copy link
Contributor Author

commented Apr 26, 2019

Ok i think i figured it out for password (see #256 ) ... but i have same problem with type: file, which is trickier ... i'm not sure how to handle that one

@tomasherman

This comment has been minimized.

Copy link
Contributor Author

commented Apr 26, 2019

this is an example of the offending yml...

get:
  summary: get timezone data
  operationId: getTimezoneData
  description: |-
    Get timezone data (also called tzdata)
  responses:
    200:
      description: Succesfully retrieved tzdata.
      schema:
        description: User specific tzdata file.
        type: file

i assume raw response could be used for this but this fails the compilation ... i wonder how to solve this ... perhaps generate response that takes fs2 stream and pipe it to raw response in the generated code?

@kelnos

This comment has been minimized.

Copy link
Member

commented Apr 26, 2019

What's the compiler error? We've supported type: file for some time now; not sure why it wouldn't work.

@blast-hardcheese

This comment has been minimized.

Copy link
Collaborator

commented Apr 26, 2019

@tomasherman akka-http has support for type: file, not sure that http4s has support for that yet. The naive implementation in akka-http uses a helper method to build a java.io.File object, which the file is streamed into.

This isn't a great solution though, I'd much rather go with something InputStream based to stream into a file or to anything else that can behave like an InputStream.

@tomasherman

This comment has been minimized.

Copy link
Contributor Author

commented Apr 29, 2019

the error for file comes during code generation phase:

[info]   java.lang.Exception: UserError(Unknown type for the following structure (type: file, class: io.swagger.v3.oas.models.media.FileSchema):
[info]   class FileSchema {
[info]       class Schema {
[info]           type: file
[info]           format: binary
[info]       }
[info]   }
[info] )
@blast-hardcheese

This comment has been minimized.

Copy link
Collaborator

commented May 1, 2019

This is likely related to
SwaggerGenerator.scala#L103-L111:

      case GetType(model) =>
        val determinedType = Option(model.getType()).fold("No type definition")(s => s"type: $s")
        val className      = model.getClass.getName
        Target.fromOption(
          Option(model.getType()),
          s"""|Unknown type for the following structure (${determinedType}, class: ${className}):
              |  ${model.toString().lines.filterNot(_.contains(": null")).mkString("\n  ")}
              |""".stripMargin
        )

where .getType() returns null, as it should be .getSchema().getType(). I wonder why they embed a Schema[_] into a FileSchema... this seems unnecessary.

Could you try using an OpenAPI 3.x spec to reproduce?

Alternately, I'm realizing that we don't have any tests for type: file in the response structure, which would indicate why this hasn't come up before.

@tomasherman

This comment has been minimized.

Copy link
Contributor Author

commented May 1, 2019

i can provide some failing test case, but is there any chance any of you guys could take a stab at this? I am already battling in two other merge requests and i don't have any more time to invest :(

@blast-hardcheese

This comment has been minimized.

Copy link
Collaborator

commented May 1, 2019

I can't promise I can get to it this week, unfortunately. Thank you for your efforts iterating on your other PRs, by the way 😄

@tomasherman

This comment has been minimized.

Copy link
Contributor Author

commented May 1, 2019

well, we either have to make it work for our use cases, or use python at work ... so not really much choice :D but thanks for the guidance ... i might get to it after all, i think i made good progress on the other PRs

@Gipetto

This comment has been minimized.

Copy link
Member

commented May 1, 2019

Another failure example, if it helps, otherwise this just a self-serving +1 to having the same issue.

      responses:
        '200':
          description: OK
          content:
            image/png:
              schema:
                type: string
                format: binary
            image/jpeg:
              schema:
                type: string
                format: binary
            application/pdf:
              schema:
                type: string
                format: binary

Produces the error:

[ERROR] Error: Unknown type for the following structure (type: string, class: io.swagger.v3.oas.models.media.BinarySchema):
  class BinarySchema {
      class Schema {
      }
      type: string
      format: binary
  }

[ERROR] Failed to generate client
com.twilio.maven.swagger.CodegenFailedException
    at com.twilio.maven.swagger.AbstractSwaggerCodegenMojo.$anonfun$guardrailTwilioTask$4 (AbstractSwaggerCodegenMojo.scala:131)
@tomasherman

This comment has been minimized.

Copy link
Contributor Author

commented May 5, 2019

I wonder how type string format binary should be represented...it seems the easiest solution would be Array[Byte] but i feel Stream[Byte] would be better as these files will probably always be files or something that might be quite large

@tomasherman

This comment has been minimized.

Copy link
Contributor Author

commented May 5, 2019

@Gipetto i believe i patched this issue with #283 but i think further improvements on how binary properties should be handled are in order

blast-hardcheese added a commit that referenced this issue May 10, 2019

Merge pull request #283 from avast/issue255
#255 improvement - Fixed issue with type:file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.