openapi-to-graphql icon indicating copy to clipboard operation
openapi-to-graphql copied to clipboard

`required` field of definitions are not being respected while generating types

Open vinaybedre opened this issue 5 years ago • 2 comments

Describe the bug required field of definitions are not being respected while generating types

To Reproduce Steps to reproduce the behavior:

  1. npm i -g openapi-to-graphql-cli
  2. openapi-to-graphql file.yaml --> file.yaml is as pasted below
swagger: "2.0"
info:
    version: 1.1.0
    title: Test server
basePath: /api/v1
host: localhost
paths:
    /user/{id}:
        get:
            operationId: getUserId
            tags:
                - users
            produces:
                - application/json
            parameters:
                - name: id
                  in: path
                  description: User Id
                  required: true
                  type: integer
                  format: int64
            responses:
                200:
                    description: A User Response
                    schema:
                        $ref: "#/definitions/UserResponse"
definitions:
    UserResponse:
        type: object
        required:
            - userId
        properties:
            userId:
                type: integer
                format: int64
            userName:
                type: string

Expected behavior

"""The start of any query"""
type Query {
  userResponse(
    """User Id"""
    id: Float!
  ): UserResponse
}

type UserResponse {
  userId: Float! <-----
  userName: String
}

instead of

"""The start of any query"""
type Query {
  userResponse(
    """User Id"""
    id: Float!
  ): UserResponse
}

type UserResponse {
  userId: Float
  userName: String
}

vinaybedre avatar Jan 22 '20 09:01 vinaybedre

@vinaybedre Thank you for the detailed issue with the OAS and expected/actual behavior. This is definitely a bug and should be working properly. I will take a look.

Alan-Cha avatar Jan 22 '20 19:01 Alan-Cha

I replicated this error using CLI version 1.7.0, the latest version.

I also checked with the current build of the library and did not have this issue. I think by releasing a new version, which we are planning on doing either this or next week, we should be able to address this problem. Keep an eye out!

Alan-Cha avatar Jan 22 '20 20:01 Alan-Cha