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

Warn user in case an OpenAPI description with inline schema is provided as input #17

Open
LorenzHW opened this issue Feb 11, 2020 · 6 comments
Labels
good first issue This issue is a good place to started contributing to this repository.

Comments

@LorenzHW
Copy link
Collaborator

Regarding Tim's comment:

Since schema references often correspond to named structs, I'm inclined to force all inlined schemas to be converted to references, either with a linter rule or a transformation.

As long as this linter rule or transformation does not exist we should display a warning that the output of gnostic-grpc might be faulty in case the user provides an OpenAPI description with inline schemas.

Example input API with inline schema:

paths:
  /inlineSchema:
    get:
      operationId: inlineSchema
      responses:
        200:
          description: succes
          content:
            application/json:
              schema:
                type: integer
                format: int32

Expected console output after running gnostic --grpc-out...:

level:WARNING  code: "" text: "An inline schema is provided. The output of gnostic-grpc might be incorrect. Consider using a reference for your schema" keys:"paths" keys:"/inlineSchema" keys:"get" keys:"responses" keys:"200" keys:"content" keys:"application/json" keys:"schema"

Example input API with reference schema:

paths:
  /referenceSchema:
    get:
      operationId: referenceSchema
      responses:
        200:
          description: success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Person'
components:
  schemas:
    Person:
      type: object
      properties:
        age:
          type: integer
          format: int64
        name:
          type: string
          example: Peter

Expected console output:
No warning regarding inline schema

@LorenzHW LorenzHW added the good first issue This issue is a good place to started contributing to this repository. label Feb 11, 2020
@LorenzHW
Copy link
Collaborator Author

@idoqo do you want to work on this?

@idoqo
Copy link

idoqo commented Feb 11, 2020

Yeah. I'd like to love to work on this one.

@LorenzHW
Copy link
Collaborator Author

Cool! LMK in case you have any questions.

@idoqo
Copy link

idoqo commented Feb 14, 2020

Hi, sorry...I was wondering what would be the best way to check if a schema in the description is inline (or referenced) as it seems to be abstracted out by the SchemasOrReference, ResponsesOrReferences, etc by gnostic.

@LorenzHW
Copy link
Collaborator Author

LorenzHW commented Mar 1, 2020

Hi. Sorry for the late response.

Yes, exactly. The function anaylzeSchema(.., schemaOrReference *openapiv3.SchemaOrReference, ..) has as input a schemaOrReference. Now, you can use the methods: schemaOrReference.GetSchema() and schemaOrReference.GetReference(). One of these functions will return something and the other one will return nil. Then you probably need some kind of check whether you are currently analyzing the paths section of the OpenAPI document. If that is the case AND schemaOrReference.GetSchema() does return a schema, a warning needs to be constructed. Does this help?

@idoqo
Copy link

idoqo commented Mar 3, 2020

Does this help?

Yes, it does a lot. I'd work with that then, thanks a lot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue This issue is a good place to started contributing to this repository.
Projects
None yet
Development

No branches or pull requests

2 participants