kogosoftwarellc / open-api

A Monorepo of various packages to power OpenAPI in node
MIT License
895 stars 237 forks source link

OpenAPI Types package, Path Item Object #879

Open dbwodlf3 opened 1 year ago

dbwodlf3 commented 1 year ago

https://github.com/kogosoftwarellc/open-api/tree/main/packages/openapi-types#readme

export type PathItemObject = OpenAPIV3_1.PathItemObject<OperationObject>;

export const PathItemObject: PathItemObject = {
  // $ref: null,
  summary: "",
  description: "",
  servers: [],
  parameters: [],
  $ref: "",
};

export type OperationObject =
  OpenAPIV3_1.OperationObject<OpenAPIV3.OperationObject>;

export const OperationObject: OperationObject = {
  tags: [],
  summary: "",
  description: "",
  externalDocs: {
    url: "",
  },
  operationId: "",
  parameters: [],
  requestBody: {
    content: {
      "application/json": {
        schema: {
          type: "object",
          properties: {},
        },
      },
    },
  },
  responses: {
    "200": {
      description: "Success",
      content: {},
    },
  },
  callbacks: {},
  deprecated: false,
  security: [],
  servers: [],
};

export type OperationObject2 =
  OpenAPIV3_1.OperationObject;

export const OperationObject: OperationObject2 = {
  tags: [],
  summary: "",
  description: "",
  externalDocs: {
    url: "",
  },
  operationId: "",
  parameters: [],
  requestBody: {
    content: {
      "application/json": {
        schema: {
          type: "object",
          properties: {},
        },
      },
    },
  },
  responses: {
    "200": {
      description: "Success",
      content: {},
    },
  },
  callbacks: {},
  deprecated: false,
  security: [],
  servers: [],
};
// it works.
PathItemObject.get = OperationObject;

// it doesn't work.
PathItemObject.post = OperationObject2;

package version is "openapi-types": "^12.1.3",

dbwodlf3 commented 1 year ago

OpenAPI 3_1 is reusing OpenAPI3 type definition, but some cases it doesn't work well.

requestBody?: ((OpenAPIV3.ReferenceObject | OpenAPIV3.RequestBodyObject) & 
                          (OpenAPIV3_1.ReferenceObject | OpenAPIV3_1.RequestBodyObject))

if requestBody is OpenAPIV3_1, it doesn't work. it works only when OpenAPIV3.RequestBodyObject