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

Error: "nullable" cannot be used without "type" #228

Open
roma0297 opened this issue Sep 15, 2021 · 2 comments
Open

Error: "nullable" cannot be used without "type" #228

roma0297 opened this issue Sep 15, 2021 · 2 comments

Comments

@roma0297
Copy link

I'm generating the following yaml spec file with openapi 3.0.0 from my kotlin backend:

    Request:
      required:
      - field1
      - field2
      - field3
      type: object
      properties:
        field1:
          type: string
        field2:
          type: string
          format: date-time
        field3:
          type: string
        field4:
          allOf:
          - $ref: '#/components/schemas/RequestVehicleConfiguration'
          - nullable: true

The interesting part here is this field4 which may be a nulllable reference.

After that I try to write a test and mock this API:

  const api = new OpenAPIBackend({ definition: this.spec });
  // Register some handlers
  api.init()

Expected behaviour: Api is initialized

Actual behaviour: Error: "nullable" cannot be used without "type"

What I tried so far:

  • Tried to use openapi-backend 4.1.0 and 4.2.0

I tried to replace

      field4:
        allOf:
        - $ref: '#/components/schemas/RequestVehicleConfiguration'
        - nullable: true

with

        vehicleConfiguration:
          $ref: '#/components/schemas/RequestVehicleConfiguration'

And it helps but I don't won't to do it manually, I would like to rely on automatic schema generation. Any ideas what I'm doing wrong? As far as I understand the schema is valid, why I cannot generate an API mock from it?

@jaecktec
Copy link

jaecktec commented Oct 4, 2021

Just dropping this here:

OAI/OpenAPI-Specification#1368

Might be a feature 'support openapi 3.1'

@robogeek
Copy link

FWIW - I'm using OpenAPI Backend to implement an application using a spec developed by a standards organization. They recently switched to using nullable: true, for which I'm getting this sort of error:

/Volumes/Evoke/esx-server/server/node_modules/ajv/lib/compile/validate/dataType.ts:26
      throw new Error('"nullable" cannot be used without "type"')
            ^
Error: "nullable" cannot be used without "type"
    at getSchemaTypes (/Volumes/Evoke/esx-server/server/node_modules/ajv/lib/compile/validate/dataType.ts:26:13)
    at typeAndKeywords (/Volumes/Evoke/esx-server/server/node_modules/ajv/lib/compile/validate/index.ts:159:31)
    at subSchemaObjCode (/Volumes/Evoke/esx-server/server/node_modules/ajv/lib/compile/validate/index.ts:147:3)
    at subschemaCode (/Volumes/Evoke/esx-server/server/node_modules/ajv/lib/compile/validate/index.ts:124:7)
    at KeywordCxt.subschema (/Volumes/Evoke/esx-server/server/node_modules/ajv/lib/compile/validate/index.ts:500:5)
    at applyPropertySchema (/Volumes/Evoke/esx-server/server/node_modules/ajv/lib/vocabularies/applicator/properties.ts:45:11)
    at Object.code (/Volumes/Evoke/esx-server/server/node_modules/ajv/lib/vocabularies/applicator/properties.ts:32:9)
    at keywordCode (/Volumes/Evoke/esx-server/server/node_modules/ajv/lib/compile/validate/index.ts:532:9)
    at /Volumes/Evoke/esx-server/server/node_modules/ajv/lib/compile/validate/index.ts:265:9
    at CodeGen.code (/Volumes/Evoke/esx-server/server/node_modules/ajv/lib/compile/codegen/index.ts:525:33)

Commenting out all uses of nullable: true fixed the problem. I see the link provided by @jaecktec but in this case it is not associated with $ref uses.

Some examples:

        x:
          type: number
          format: float
          description: A value on an x axis.
          example: 1.0
          # nullable: true
          default: null

        targets:
          type: array
          description: An list of target objects.
          # nullable: true
          default: null
          items:
            $ref: '#/components/schemas/target'

    userIdentifier:
        oneOf: [
          {type: integer},
          {type: string}
        ]
        description: User generated numeric or string identifier
        example: 99
        # nullable: true
        default: null

        programDescriptions:
          type: array
          description: A list of programDescriptions
          # nullable: true
          default: null
          items:
            required:
              - URL
            properties:
              URL:
                type: string
                # format: uri
                description: a human or machine readable program description
                example: www.myCorporation.com/myProgramDescription

The last one also demonstrates another unrelated issue - that format: uri is not recognized.

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

No branches or pull requests

3 participants