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

Closed
tomasherman opened this issue Apr 26, 2019 · 17 comments
Labels
bug Unexpected behaviour for functionality that either was intended to work, or has worked in the past help wanted Easy to moderately difficult issues that don't require deep knowledge or architectural thought

Comments

@tomasherman
Copy link
Contributor

tomasherman 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
Copy link
Contributor Author

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
Copy link
Contributor Author

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
Copy link
Member

kelnos 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
Copy link
Member

@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
Copy link
Contributor Author

tomasherman 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
Copy link
Member

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.

@blast-hardcheese blast-hardcheese added bug Unexpected behaviour for functionality that either was intended to work, or has worked in the past help wanted Easy to moderately difficult issues that don't require deep knowledge or architectural thought labels May 1, 2019
@tomasherman
Copy link
Contributor Author

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
Copy link
Member

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
Copy link
Contributor Author

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
Copy link

Gipetto 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
Copy link
Contributor Author

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
Copy link
Contributor Author

@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
#255 improvement - Fixed issue with type:file
@rethab
Copy link

rethab commented Aug 9, 2019

There's a similar issue with the format type email. I don't think this one requires special handling (see https://swagger.io/specification/#data-types) but it is also not disallowed.

@nick-bauer
Copy link

nick-bauer commented Dec 26, 2019

I am running into a similar issue with type: array

"FooBatch": {
        "properties": {
          "foos": {
            "items": {
              "$ref": "#/components/schemas/Foo"
            },
            "type": "array"
          }
        }
      }

[31mError:�[0mUnknown type for the following structure (No type definition, class: io.swagger.v3.oas.models.media.Schema):

class Schema {
    properties: {foos=class ArraySchema {
        class Schema {
        }
        type: array
        items: class Schema {
            $ref: #/components/schemas/Foo
        }
    }}
}

@blast-hardcheese
Copy link
Member

@nick-bauer: What's the context around FooBatch? Where in the document is it coming from?

@blast-hardcheese
Copy link
Member

Following up, as this bit one of my coworkers -- It turns out that the assumption of type: array with an items that doesn't have a definite type can cause this error.

@blast-hardcheese
Copy link
Member

#1407 improves the situation referred to by @nick-bauer -- I unified the different type transformation logic, which was causing issues with $refs inside of array.

Closing this, thank you 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Unexpected behaviour for functionality that either was intended to work, or has worked in the past help wanted Easy to moderately difficult issues that don't require deep knowledge or architectural thought
Projects
None yet
Development

No branches or pull requests

6 participants