diff --git a/packages/core/src/process/content.ts b/packages/core/src/process/content.ts index 1df8e7f..2813555 100644 --- a/packages/core/src/process/content.ts +++ b/packages/core/src/process/content.ts @@ -159,6 +159,7 @@ export function applyCodegenContentEncoding(content: CodegenContent, encodingSpe if (requiresMetadata(content.encoding)) { const newSchema = createObjectSchema(content.mediaType.mimeType, content.schema, content.schema.purpose, state) + newSchema.contentMediaType = content.mediaType newSchema.properties = idx.create(allProperties) for (const name of idx.allKeys(newSchema.properties)) { diff --git a/packages/core/src/process/schema/all-of.ts b/packages/core/src/process/schema/all-of.ts index 995ca71..98e8050 100644 --- a/packages/core/src/process/schema/all-of.ts +++ b/packages/core/src/process/schema/all-of.ts @@ -54,6 +54,7 @@ function toCodegenAllOfSchemaNative(apiSchema: OpenAPIX.SchemaObject, naming: Sc type: 'allOf', format: null, schemaType: CodegenSchemaType.ALLOF, + contentMediaType: null, component: null, deprecated: false, examples: null, @@ -142,6 +143,7 @@ function toCodegenAllOfSchemaObject(apiSchema: OpenAPIX.SchemaObject, naming: Sc type: 'object', format: null, schemaType: CodegenSchemaType.OBJECT, + contentMediaType: null, component: null, deprecated: false, diff --git a/packages/core/src/process/schema/any-of.ts b/packages/core/src/process/schema/any-of.ts index 6df040b..4ddf778 100644 --- a/packages/core/src/process/schema/any-of.ts +++ b/packages/core/src/process/schema/any-of.ts @@ -51,6 +51,7 @@ function toCodegenAnyOfSchemaNative(apiSchema: OpenAPIX.SchemaObject, naming: Sc type: 'anyOf', format: null, schemaType: CodegenSchemaType.ANYOF, + contentMediaType: null, component: null, deprecated: false, examples: null, @@ -136,6 +137,7 @@ function toCodegenAnyOfSchemaObject(apiSchema: OpenAPIX.SchemaObject, naming: Sc type: 'object', format: null, schemaType: CodegenSchemaType.OBJECT, + contentMediaType: null, component: null, deprecated: false, diff --git a/packages/core/src/process/schema/array.ts b/packages/core/src/process/schema/array.ts index 9f8a646..ff03693 100644 --- a/packages/core/src/process/schema/array.ts +++ b/packages/core/src/process/schema/array.ts @@ -41,6 +41,7 @@ export function toCodegenArraySchema(apiSchema: OpenAPIX.SchemaObject, naming: S type: 'array', format: apiSchema.format || null, schemaType: CodegenSchemaType.ARRAY, + contentMediaType: null, component: componentSchemaUsage, nativeType, @@ -84,6 +85,7 @@ export function createArraySchema(component: CodegenSchemaUsage, purpose: Codege type: 'array', format: null, schemaType: CodegenSchemaType.ARRAY, + contentMediaType: null, description: null, title: null, vendorExtensions: null, diff --git a/packages/core/src/process/schema/boolean.ts b/packages/core/src/process/schema/boolean.ts index 07af967..836ca9a 100644 --- a/packages/core/src/process/schema/boolean.ts +++ b/packages/core/src/process/schema/boolean.ts @@ -27,6 +27,7 @@ export function toCodegenBooleanSchema(apiSchema: OpenAPIX.SchemaObject, naming: type: apiSchema.type, format: format || null, schemaType: CodegenSchemaType.BOOLEAN, + contentMediaType: null, nativeType, component: null, diff --git a/packages/core/src/process/schema/enum.ts b/packages/core/src/process/schema/enum.ts index 3e6b77b..7c36149 100644 --- a/packages/core/src/process/schema/enum.ts +++ b/packages/core/src/process/schema/enum.ts @@ -95,6 +95,7 @@ export function toCodegenEnumSchema(apiSchema: OpenAPIX.SchemaObject, naming: Sc type: apiSchema.type, format: apiSchema.format || null, schemaType: CodegenSchemaType.ENUM, + contentMediaType: null, component: null, nativeType, diff --git a/packages/core/src/process/schema/hierarchy.ts b/packages/core/src/process/schema/hierarchy.ts index c892213..ae846ee 100644 --- a/packages/core/src/process/schema/hierarchy.ts +++ b/packages/core/src/process/schema/hierarchy.ts @@ -36,6 +36,7 @@ export function toCodegenHierarchySchema(apiSchema: OpenAPIX.SchemaObject, namin type: 'hierarchy', format: null, schemaType: CodegenSchemaType.HIERARCHY, + contentMediaType: null, component: null, deprecated: false, examples: null, diff --git a/packages/core/src/process/schema/index.ts b/packages/core/src/process/schema/index.ts index 86f9aa9..a337e9c 100644 --- a/packages/core/src/process/schema/index.ts +++ b/packages/core/src/process/schema/index.ts @@ -232,6 +232,7 @@ function toCodegenSchema(apiSchema: OpenAPIX.SchemaObject, $ref: string | undefi type, format: format || null, schemaType: toCodegenSchemaType(type, format), + contentMediaType: null, nativeType, component: null, diff --git a/packages/core/src/process/schema/interface.ts b/packages/core/src/process/schema/interface.ts index 1f5d47c..4e5cf09 100644 --- a/packages/core/src/process/schema/interface.ts +++ b/packages/core/src/process/schema/interface.ts @@ -60,6 +60,7 @@ export function createIfNotExistsCodegenInterfaceSchema(schema: CodegenObjectSch description: schema.description, title: schema.title, schemaType: CodegenSchemaType.INTERFACE, + contentMediaType: null, component: null, deprecated: schema.deprecated, diff --git a/packages/core/src/process/schema/map.ts b/packages/core/src/process/schema/map.ts index 8b9c1c4..a5906bb 100644 --- a/packages/core/src/process/schema/map.ts +++ b/packages/core/src/process/schema/map.ts @@ -51,6 +51,7 @@ export function toCodegenMapSchema(apiSchema: OpenAPIX.SchemaObject, naming: Sco type: 'object', format: apiSchema.format || null, schemaType: CodegenSchemaType.MAP, + contentMediaType: null, component: componentSchemaUsage, nativeType, diff --git a/packages/core/src/process/schema/null.ts b/packages/core/src/process/schema/null.ts index d248271..157a961 100644 --- a/packages/core/src/process/schema/null.ts +++ b/packages/core/src/process/schema/null.ts @@ -24,6 +24,7 @@ export function toCodegenNullSchema(apiSchema: OpenAPIX.SchemaObject, naming: Sc type: 'null', format: null, schemaType: CodegenSchemaType.NULL, + contentMediaType: null, nativeType, component: null, diff --git a/packages/core/src/process/schema/numeric.ts b/packages/core/src/process/schema/numeric.ts index e2f6219..f865025 100644 --- a/packages/core/src/process/schema/numeric.ts +++ b/packages/core/src/process/schema/numeric.ts @@ -34,6 +34,7 @@ export function toCodegenNumericSchema(apiSchema: OpenAPIX.SchemaObject, naming: type: apiSchema.type, format: apiSchema.format || null, schemaType, + contentMediaType: null, nativeType, component: null, diff --git a/packages/core/src/process/schema/object.ts b/packages/core/src/process/schema/object.ts index 627ea95..53678d9 100644 --- a/packages/core/src/process/schema/object.ts +++ b/packages/core/src/process/schema/object.ts @@ -65,6 +65,7 @@ function toCodegenObjectSchemaObject(apiSchema: OpenAPIX.SchemaObject, naming: S type: 'object', format: apiSchema.format || null, schemaType: CodegenSchemaType.OBJECT, + contentMediaType: null, interface: null, implements: null, parents: null, @@ -120,6 +121,7 @@ function toCodegenObjectSchemaInterface(apiSchema: OpenAPIX.SchemaObject, naming type: 'object', format: apiSchema.format || null, schemaType: CodegenSchemaType.INTERFACE, + contentMediaType: null, implementation: null, implementors: null, parents: null, @@ -211,6 +213,7 @@ export function createObjectSchema(suggestedName: string, scope: CodegenScope | type: 'object', format: null, schemaType: CodegenSchemaType.OBJECT, + contentMediaType: null, abstract: false, properties: null, additionalProperties: null, diff --git a/packages/core/src/process/schema/one-of.ts b/packages/core/src/process/schema/one-of.ts index bc18a70..321f79a 100644 --- a/packages/core/src/process/schema/one-of.ts +++ b/packages/core/src/process/schema/one-of.ts @@ -48,6 +48,7 @@ function toCodegenOneOfSchemaNative(apiSchema: OpenAPIX.SchemaObject, naming: Sc type: 'oneOf', format: null, schemaType: CodegenSchemaType.ONEOF, + contentMediaType: null, component: null, deprecated: false, examples: null, @@ -131,6 +132,7 @@ function toCodegenOneOfSchemaInterface(apiSchema: OpenAPIX.SchemaObject, naming: type: 'object', format: null, schemaType: CodegenSchemaType.INTERFACE, + contentMediaType: null, component: null, deprecated: false, @@ -258,6 +260,7 @@ export function createOneOfSchema(suggestedName: string, scope: CodegenScope | n type: 'oneOf', format: null, schemaType: CodegenSchemaType.ONEOF, + contentMediaType: null, component: null, deprecated: false, examples: null, diff --git a/packages/core/src/process/schema/string.ts b/packages/core/src/process/schema/string.ts index 41cf5e6..2a4812d 100644 --- a/packages/core/src/process/schema/string.ts +++ b/packages/core/src/process/schema/string.ts @@ -35,6 +35,7 @@ export function toCodegenStringSchema(apiSchema: OpenAPIX.SchemaObject, naming: type: apiSchema.type, format: format || null, schemaType, + contentMediaType: null, nativeType, component: null, diff --git a/packages/core/src/process/schema/wrapper.ts b/packages/core/src/process/schema/wrapper.ts index 0eea2fe..0d51365 100644 --- a/packages/core/src/process/schema/wrapper.ts +++ b/packages/core/src/process/schema/wrapper.ts @@ -43,6 +43,7 @@ export function createWrapperSchemaUsage(suggestedName: string, scope: CodegenSc type: wrap.schema.type, format: null, schemaType: CodegenSchemaType.WRAPPER, + contentMediaType: null, property, implements: null, description: null, diff --git a/packages/types/src/types.ts b/packages/types/src/types.ts index 4203c28..64f399d 100644 --- a/packages/types/src/types.ts +++ b/packages/types/src/types.ts @@ -553,6 +553,9 @@ export interface CodegenSchema extends CodegenSchemaInfo { */ purpose: CodegenSchemaPurpose + /** If this schema was created to represent a specific request content type, this property will be populated with that media type. */ + contentMediaType: CodegenMediaType | null + title: string | null /** OpenAPI type */ diff --git a/packages/utils/src/content.ts b/packages/utils/src/content.ts new file mode 100644 index 0000000..4c04dfd --- /dev/null +++ b/packages/utils/src/content.ts @@ -0,0 +1,17 @@ +import { CodegenSchema, isCodegenObjectLikeSchema, isCodegenArraySchema } from '@openapi-generator-plus/types' + +/** + * Return the "value" schema for a metadata schema that might be either single-valued or an array. + * Otherwise return undefined if such a schema cannot be found. + * @param schema + * @returns + */ +export function valueSchemaForMetadataSchema(schema: CodegenSchema): CodegenSchema | undefined { + if (isCodegenObjectLikeSchema(schema) && schema.properties && schema.properties.value) { + return schema.properties.value.schema + } else if (isCodegenArraySchema(schema) && schema.component && isCodegenObjectLikeSchema(schema.component.schema) && schema.component.schema.properties && schema.component.schema.properties.value) { + return schema.component.schema.properties.value.schema + } else { + return undefined + } +} \ No newline at end of file diff --git a/packages/utils/src/index.ts b/packages/utils/src/index.ts index 1368fa0..1954d20 100644 --- a/packages/utils/src/index.ts +++ b/packages/utils/src/index.ts @@ -1,2 +1,3 @@ export * from './stringify' export * from './objects' +export * from './content'