Force Hero
Force Hero

Reputation: 3252

Swagger stating "should NOT have additional properties additionalProperty: schema" for a reusable enum

I'm trying to create an enum as a reusable object in my swagger and swagger is erroring with:

Structural error at components.schemas.Project.properties.location
should NOT have additional properties
additionalProperty: schema
Jump to line 47

I have the enum specified in the components/schemas section and I am then referencing it using $ref: '#/components/schemas/Registry'. I was trying to follow the example here: https://swagger.io/docs/specification/data-models/enums/

This is the full swagger file:

openapi: 3.0.3
info:
  title: My API
  description: |-
    Blah
  contact:
    email: [email protected]
  version: 1.0.0
externalDocs:
  description: Find out more about blah
  url: http://blah.io
paths:
  /credits-received:
    post:
      tags:
        - Credits Received
      operationId: creditsReceived
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreditsReceivedData'
        required: true
      responses:
        '200':
          description: Successful operation

components:
  schemas:
    CreditsReceivedData:
      required:
        - project
      type: object
      properties:
        project:
          $ref: '#/components/schemas/Project'

    Project:
      required:
        - name
        - registry
      type: object
      properties:
        name:
          type: string
          example: "Project 1"
        registry:
          type: string
          example: "My Registry"
          schema:
            $ref: '#/components/schemas/Registry'
    Registry:
      type: string
      enum:
        - My Registry 1
        - My registry 2

Upvotes: 0

Views: 4238

Answers (1)

Force Hero
Force Hero

Reputation: 3252

I solved this by replacing

        registry:
          type: string
          example: "My Registry"
          schema:
            $ref: '#/components/schemas/Registry'

with

        registry:
          $ref: '#/components/schemas/Registry'

Basically remove the schema attribute, just put the $ref directly under the property (registry in this case).

Upvotes: 1

Related Questions