Skip to content

Commit

Permalink
Merge pull request #56 from Dakskihedron/main
Browse files Browse the repository at this point in the history
feat: improve support for multipart requests
  • Loading branch information
karlvr committed Jul 1, 2024
2 parents 557543e + 5b5d74c commit 7c9061c
Show file tree
Hide file tree
Showing 20 changed files with 51 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .changeset/green-mugs-speak.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@openapi-generator-plus/core": minor
"@openapi-generator-plus/types": minor
"@openapi-generator-plus/utils": minor
---

Improve support for schemas created to support different content encodings
1 change: 1 addition & 0 deletions packages/core/src/process/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/process/schema/all-of.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -142,6 +143,7 @@ function toCodegenAllOfSchemaObject(apiSchema: OpenAPIX.SchemaObject, naming: Sc
type: 'object',
format: null,
schemaType: CodegenSchemaType.OBJECT,
contentMediaType: null,
component: null,
deprecated: false,

Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/process/schema/any-of.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -136,6 +137,7 @@ function toCodegenAnyOfSchemaObject(apiSchema: OpenAPIX.SchemaObject, naming: Sc
type: 'object',
format: null,
schemaType: CodegenSchemaType.OBJECT,
contentMediaType: null,
component: null,
deprecated: false,

Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/process/schema/array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand Down Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/process/schema/boolean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand Down
1 change: 1 addition & 0 deletions packages/core/src/process/schema/enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand Down
1 change: 1 addition & 0 deletions packages/core/src/process/schema/hierarchy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/process/schema/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand Down
1 change: 1 addition & 0 deletions packages/core/src/process/schema/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand Down
1 change: 1 addition & 0 deletions packages/core/src/process/schema/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand Down
1 change: 1 addition & 0 deletions packages/core/src/process/schema/null.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export function toCodegenNullSchema(apiSchema: OpenAPIX.SchemaObject, naming: Sc
type: 'null',
format: null,
schemaType: CodegenSchemaType.NULL,
contentMediaType: null,
nativeType,
component: null,

Expand Down
1 change: 1 addition & 0 deletions packages/core/src/process/schema/numeric.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export function toCodegenNumericSchema(apiSchema: OpenAPIX.SchemaObject, naming:
type: apiSchema.type,
format: apiSchema.format || null,
schemaType,
contentMediaType: null,
nativeType,
component: null,

Expand Down
3 changes: 3 additions & 0 deletions packages/core/src/process/schema/object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions packages/core/src/process/schema/one-of.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -131,6 +132,7 @@ function toCodegenOneOfSchemaInterface(apiSchema: OpenAPIX.SchemaObject, naming:
type: 'object',
format: null,
schemaType: CodegenSchemaType.INTERFACE,
contentMediaType: null,
component: null,
deprecated: false,

Expand Down Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/process/schema/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export function toCodegenStringSchema(apiSchema: OpenAPIX.SchemaObject, naming:
type: apiSchema.type,
format: format || null,
schemaType,
contentMediaType: null,
nativeType,
component: null,

Expand Down
1 change: 1 addition & 0 deletions packages/core/src/process/schema/wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions packages/types/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
17 changes: 17 additions & 0 deletions packages/utils/src/content.ts
Original file line number Diff line number Diff line change
@@ -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
}
}
1 change: 1 addition & 0 deletions packages/utils/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './stringify'
export * from './objects'
export * from './content'

0 comments on commit 7c9061c

Please sign in to comment.