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

Exegesis 3.0.0 using updated ajv outputs issues with OpenAPI spec, but 2.0.0 did not #262

Closed
acotty opened this issue May 15, 2021 · 5 comments
Labels

Comments

@acotty
Copy link

acotty commented May 15, 2021

I have upgraded from exegesis-express 2.0.0 to 3.0.0 and as a consequence upgraded exegesis to 3.0.0. In When using 2.0.0 with my Openapi yaml file I did not get any warning/errors, but with 3.0.0 I get the following output:

"strict mode: missing type "object" for keyword "required" at "#/properties/value" (strictTypes)"

I will have a look at the ajv code, but thought I should raise an issue ASAP in case other people have the same problem or if someone knows how to fix the issue.

I have traced the output to the following:
File: https://github.com/exegesis-js/exegesis/blob/master/src/oas3/Schema/validators.ts
Line: const validate = ajv.compile(schema);
Line#: 223

The offending problem is to do with the $ref: "#/components/schemas/ExceptionResponse", which is defined as:

    ExceptionResponse:
      description: An error has occured in the system and this object contains information to diagnose the problem.
      required:
        - errorId
        - errorCode
        - message
      properties:
        errorId:
          description: Unique error Id used for code debugging if info stored
          type: string
        errorCode:
          description: Error code from system used to track nature of error.
          type: string
        message:
          description: User friendly version of the error.
          type: string
        detail:
          description: Error detail. Only returned if service is in diagnostic mode.
          type: string

The full openapi file is

openapi: 3.0.0
info:
  title: Example API
  description: Example API
  version: 0.0.1
  license:
    name: Restricted

servers:
  - url: /

paths:
  "/add/{x}/{y}":
    x-exegesis-controller: math
    get:
      summary: Get the sum of two numbers.
      description: X + Y = JSON
      operationId: add
      parameters:
        - name: x
          description: Left operand
          in: path
          required: true
          schema:
            type: number
        - name: y
          description: Left operand
          in: path
          required: true
          schema:
            type: number
      responses:
        "200":
          description: The product of numbers.
          x-gulp-openapi-code-generator-outcome: success
          content:
            "*/*":
              schema:
                $ref: "#/components/schemas/BinaryResult"
        '400':
          description: Bad request
          x-gulp-openapi-code-generator-outcome: badRequestError
        '405':
          description: Bad input data
          x-gulp-openapi-code-generator-outcome: badInputError
          content:
            "*/*":
              schema:
                $ref: "#/components/schemas/ExceptionResponse"
        "500":
          x-gulp-openapi-code-generator-outcome: error
          description: Error
          content:
            "*/*":
              schema:
                $ref: "#/components/schemas/ExceptionResponse"
  "/addProtected/{x}/{y}":
    x-exegesis-controller: math
    get:
      summary: Get the sum of two numbers.
      description: X + Y = JSON
      operationId: addProtected
      security:
#        - addBasicAuth: []
        - addOauth2: ['readOnly']
      parameters:
        - name: x
          description: Left operand
          in: path
          required: true
          schema:
            type: number
        - name: y
          description: Left operand
          in: path
          required: true
          schema:
            type: number
      responses:
        "200":
          description: The product of numbers.
          x-gulp-openapi-code-generator-outcome: success
          content:
            "*/*":
              schema:
                $ref: "#/components/schemas/BinaryResult"
        '400':
          description: Bad request
          x-gulp-openapi-code-generator-outcome: badRequestError
        '405':
          description: Bad input data
          x-gulp-openapi-code-generator-outcome: badInputError
          content:
            "*/*":
              schema:
                $ref: "#/components/schemas/ExceptionResponse"
        "500":
          x-gulp-openapi-code-generator-outcome: error
          description: Error
          content:
            "*/*":
              schema:
                $ref: "#/components/schemas/ExceptionResponse"


components:
  schemas:

    Add:
      description: A result from a binary operation.
      type: object
      required:
        - x
        - y
      properties:
        x:
          description: Left operand
          type: number
        y:
          description: Right operand
          type: number

    BinaryResult:
      description: A result from a binary operation.
      type: object
      required:
        - x
        - y
        - operation
        - result
      properties:
        x:
          description: Left operand
          type: number
        y:
          description: Right operand
          type: number
        operation:
          description: Operation
          type: string
        result:
          description: Result
          type: number
    ExceptionResponse:
      description: An error has occured in the system and this object contains information to diagnose the problem.
      required:
        - errorId
        - errorCode
        - message
      properties:
        errorId:
          description: Unique error Id used for code debugging if info stored
          type: string
        errorCode:
          description: Error code from system used to track nature of error.
          type: string
        message:
          description: User friendly version of the error.
          type: string
        detail:
          description: Error detail. Only returned if service is in diagnostic mode.
          type: string
  securitySchemes:
    # Commented out, but can be used for testing if needed
    # addBasicAuth:
    #   type: http
    #   scheme: basic
    addOauth2:
      type: oauth2
      description: A request with an oauth token.
      flows:
        #implicit:
        authorizationCode:
        #password:
          authorizationUrl: 'https://localhost:9443/oauth2/authorize'
          tokenUrl: 'http://localhost:9443/oauth2/token'
          scopes:
            readOnly: "Read only scope."

@jwalton
Copy link
Contributor

jwalton commented May 15, 2021 via email

@acotty
Copy link
Author

acotty commented May 15, 2021

They are printed to the console. They are turned off by adding "strict: false" to the "new Ajv(....)" call, but then I get another block of warnings to do with date-time strings in my more complex yaml file that is based on the swagger petstore example (https://github.com/swagger-api/swagger-petstore/blob/master/src/main/resources/openapi.yaml) , which I have attached.

The messages not turned off by adding the strict: false are
unknown format "date-time" ignored in schema at path "#/properties/value/properties/shipDate"

I have logged an issue with ajv about the xml: and date-time issues in the petstore example.

I would be inclined to provide an option to allow the strict: false or other options to be passed to ajv so that in the future end users can selectively control ajv options if they want.

FYI: Attached is the yaml file I am using after adding .txt to it to please github....
PetStore_oas3.yaml.txt

@jwalton
Copy link
Contributor

jwalton commented May 15, 2021

It looks like ajv moved the "date-time" format into the ajv-formats project at some point.

@jwalton
Copy link
Contributor

jwalton commented May 15, 2021

🎉 This issue has been resolved in version 3.0.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@acotty
Copy link
Author

acotty commented May 16, 2021

@jwalton Thanks very much for the very quick update. I have no warnings now. I can continue implementing the rest of the petstore api code to interface to the database using typeorm that i have not implemented yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants