Using $defs in API Gateway Models

0

I am working on an API Gateway api using the Serverless Framework. The project contains a json-schema which apparently is used to create a model in API Gateway. Recently, I started to use the $defs element in the schema (https://json-schema.org/understanding-json-schema/structuring.html#defs), which is a way to re-use definitions within the same schema (pasting my schema below). However, no my deployments are failing:

Error: CREATE_FAILED: ApiGatewayMethodV1PreviewsPostApplicationJsonModel (AWS::ApiGateway::Model) Resource handler returned message: “Invalid model specified: Validation Result: warnings : [], errors : [Invalid model schema > specified. Unsupported keyword(s): [“$defs”], Model reference must be in canonical form, Model reference must be in canonical form] (Service: ApiGateway, Status Code: 400, Request ID: 7048dc90-7bb4-4259-bed8-50d7a93963d9, Extended Request ID: null)”

This probably means that $defs is not supported in JSON schema draft 4? Any other way to avoid duplications in the schema file? Here is my schema (Typescript but you get the idea):

export const inputSchema = {
  type: 'object',
  properties: {
    body: {
      type: 'object',
      oneOf: [
        {
          properties: {
            input: { type: 'string' },
            options: { "$ref": "#/$defs/options" },
          },
          required: ['input'],
        },
        {
          properties: {
            data: { type: 'string' },
            options: { "$ref": "#/$defs/options" },
          },
          required: ['data'],
        },
      ],
    },
  },
  $defs: {
    options: {
      type: 'object',
      properties: {
        camera: { type: 'string' },
        auto_center: { type: 'boolean' },
        view_all: { type: 'boolean' },
      },
    },
  },
};
Keine Antworten

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen