Skip to content

Commit

Permalink
Merge pull request #745 from hey-api/fix/one-of-composition-properties
Browse files Browse the repository at this point in the history
fix: handle properties in one-of composition
  • Loading branch information
mrlubos authored Jul 4, 2024
2 parents 88f79bf + 342772a commit 0e14810
Show file tree
Hide file tree
Showing 24 changed files with 381 additions and 53 deletions.
5 changes: 5 additions & 0 deletions .changeset/unlucky-birds-work.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@hey-api/openapi-ts': patch
---

fix: handle properties in one-of composition
74 changes: 47 additions & 27 deletions packages/openapi-ts/src/openApi/v3/parser/getModelComposition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,33 +116,53 @@ export const getModelComposition = ({

if (properties.length) {
const foundComposition = findModelComposition(definition);
if (foundComposition?.type === 'one-of') {
composition.properties.forEach((property) => {
property.properties = [...property.properties, ...properties];
});
} else {
composition.properties = [
...composition.properties,
{
$refs: [],
base: 'unknown',
description: '',
enum: [],
enums: [],
export: 'interface',
imports: [],
in: '',
isDefinition: false,
isNullable: false,
isReadOnly: false,
isRequired: false,
link: null,
name: 'properties',
properties,
template: null,
type: 'unknown',
},
];
if (foundComposition) {
const propertiesProperty: Model = {
$refs: [],
base: 'unknown',
description: '',
enum: [],
enums: [],
export: 'interface',
imports: [],
in: '',
isDefinition: false,
isNullable: false,
isReadOnly: false,
isRequired: false,
link: null,
name: 'properties',
properties,
template: null,
type: 'unknown',
};

if (foundComposition.type === 'one-of') {
composition.properties = [
{
...composition,
base: '',
description: null,
enum: [],
in: '',
isDefinition: false,
isNullable: false,
isReadOnly: false,
isRequired: true,
link: null,
name: '',
template: null,
type: '',
},
propertiesProperty,
];
composition.export = 'all-of';
} else {
composition.properties = [
...composition.properties,
propertiesProperty,
];
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1709,6 +1709,32 @@ export const $ModelWithBackticksInDescription = {
}
} as const;
export const $ModelWithOneOfAndProperties = {
type: 'object',
oneOf: [
{
'$ref': '#/components/parameters/SimpleParameter'
},
{
'$ref': '#/components/schemas/NonAsciiStringæøåÆØÅöôêÊ字符串'
}
],
required: ['baz', 'qux'],
properties: {
baz: {
type: 'integer',
format: 'uint16',
minimum: 0,
nullable: true
},
qux: {
type: 'integer',
format: 'uint8',
minimum: 0
}
}
} as const;
export const $ParameterSimpleParameterUnused = {
description: 'Model used to test deduplication strategy (unused)',
type: 'string'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -783,10 +783,9 @@ export type NestedAnyOfArraysNullable = {

export type CompositionWithOneOfAndProperties = {
foo: ParameterSimpleParameter;
baz: number | null;
qux: number;
} | {
bar: NonAsciiStringæøåÆØÅöôêÊ字符串;
} & {
baz: number | null;
qux: number;
};
Expand Down Expand Up @@ -958,6 +957,11 @@ export type ModelWithBackticksInDescription = {
template?: string;
};

export type ModelWithOneOfAndProperties = ParameterSimpleParameter | NonAsciiStringæøåÆØÅöôêÊ字符串 & {
baz: number | null;
qux: number;
};

/**
* Model used to test deduplication strategy (unused)
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1709,6 +1709,32 @@ export const $ModelWithBackticksInDescription = {
}
} as const;
export const $ModelWithOneOfAndProperties = {
type: 'object',
oneOf: [
{
'$ref': '#/components/parameters/SimpleParameter'
},
{
'$ref': '#/components/schemas/NonAsciiStringæøåÆØÅöôêÊ字符串'
}
],
required: ['baz', 'qux'],
properties: {
baz: {
type: 'integer',
format: 'uint16',
minimum: 0,
nullable: true
},
qux: {
type: 'integer',
format: 'uint8',
minimum: 0
}
}
} as const;
export const $ParameterSimpleParameterUnused = {
description: 'Model used to test deduplication strategy (unused)',
type: 'string'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -687,10 +687,9 @@ export type NestedAnyOfArraysNullable = {

export type CompositionWithOneOfAndProperties = {
foo: ParameterSimpleParameter;
baz: number | null;
qux: number;
} | {
bar: NonAsciiStringæøåÆØÅöôêÊ字符串;
} & {
baz: number | null;
qux: number;
};
Expand Down Expand Up @@ -835,6 +834,11 @@ export type ModelWithBackticksInDescription = {
template?: string;
};

export type ModelWithOneOfAndProperties = ParameterSimpleParameter | NonAsciiStringæøåÆØÅöôêÊ字符串 & {
baz: number | null;
qux: number;
};

/**
* Model used to test deduplication strategy (unused)
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1709,6 +1709,32 @@ export const $ModelWithBackticksInDescription = {
}
} as const;
export const $ModelWithOneOfAndProperties = {
type: 'object',
oneOf: [
{
'$ref': '#/components/parameters/SimpleParameter'
},
{
'$ref': '#/components/schemas/NonAsciiStringæøåÆØÅöôêÊ字符串'
}
],
required: ['baz', 'qux'],
properties: {
baz: {
type: 'integer',
format: 'uint16',
minimum: 0,
nullable: true
},
qux: {
type: 'integer',
format: 'uint8',
minimum: 0
}
}
} as const;
export const $ParameterSimpleParameterUnused = {
description: 'Model used to test deduplication strategy (unused)',
type: 'string'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -783,10 +783,9 @@ export type NestedAnyOfArraysNullable = {

export type CompositionWithOneOfAndProperties = {
foo: ParameterSimpleParameter;
baz: number | null;
qux: number;
} | {
bar: NonAsciiStringæøåÆØÅöôêÊ字符串;
} & {
baz: number | null;
qux: number;
};
Expand Down Expand Up @@ -958,6 +957,11 @@ export type ModelWithBackticksInDescription = {
template?: string;
};

export type ModelWithOneOfAndProperties = ParameterSimpleParameter | NonAsciiStringæøåÆØÅöôêÊ字符串 & {
baz: number | null;
qux: number;
};

/**
* Model used to test deduplication strategy (unused)
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -687,10 +687,9 @@ export type NestedAnyOfArraysNullable = {

export type CompositionWithOneOfAndProperties = {
foo: ParameterSimpleParameter;
baz: number | null;
qux: number;
} | {
bar: NonAsciiStringæøåÆØÅöôêÊ字符串;
} & {
baz: number | null;
qux: number;
};
Expand Down Expand Up @@ -835,6 +834,11 @@ export type ModelWithBackticksInDescription = {
template?: string;
};

export type ModelWithOneOfAndProperties = ParameterSimpleParameter | NonAsciiStringæøåÆØÅöôêÊ字符串 & {
baz: number | null;
qux: number;
};

/**
* Model used to test deduplication strategy (unused)
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -750,10 +750,9 @@ export type NestedAnyOfArraysNullable = {

export type CompositionWithOneOfAndProperties = {
foo: ParameterSimpleParameter;
baz: number | null;
qux: number;
} | {
bar: NonAsciiStringæøåÆØÅöôêÊ字符串;
} & {
baz: number | null;
qux: number;
};
Expand Down Expand Up @@ -914,6 +913,11 @@ export type ModelWithBackticksInDescription = {
template?: string;
};

export type ModelWithOneOfAndProperties = ParameterSimpleParameter | NonAsciiStringæøåÆØÅöôêÊ字符串 & {
baz: number | null;
qux: number;
};

/**
* Model used to test deduplication strategy (unused)
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1709,6 +1709,32 @@ export const $ModelWithBackticksInDescription = {
}
} as const;
export const $ModelWithOneOfAndProperties = {
type: 'object',
oneOf: [
{
'$ref': '#/components/parameters/SimpleParameter'
},
{
'$ref': '#/components/schemas/NonAsciiStringæøåÆØÅöôêÊ字符串'
}
],
required: ['baz', 'qux'],
properties: {
baz: {
type: 'integer',
format: 'uint16',
minimum: 0,
nullable: true
},
qux: {
type: 'integer',
format: 'uint8',
minimum: 0
}
}
} as const;
export const $ParameterSimpleParameterUnused = {
description: 'Model used to test deduplication strategy (unused)',
type: 'string'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -783,10 +783,9 @@ export type NestedAnyOfArraysNullable = {

export type CompositionWithOneOfAndProperties = {
foo: ParameterSimpleParameter;
baz: number | null;
qux: number;
} | {
bar: NonAsciiStringæøåÆØÅöôêÊ字符串;
} & {
baz: number | null;
qux: number;
};
Expand Down Expand Up @@ -958,6 +957,11 @@ export type ModelWithBackticksInDescription = {
template?: string;
};

export type ModelWithOneOfAndProperties = ParameterSimpleParameter | NonAsciiStringæøåÆØÅöôêÊ字符串 & {
baz: number | null;
qux: number;
};

/**
* Model used to test deduplication strategy (unused)
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1709,6 +1709,32 @@ export const $ModelWithBackticksInDescription = {
}
} as const;
export const $ModelWithOneOfAndProperties = {
type: 'object',
oneOf: [
{
'$ref': '#/components/parameters/SimpleParameter'
},
{
'$ref': '#/components/schemas/NonAsciiStringæøåÆØÅöôêÊ字符串'
}
],
required: ['baz', 'qux'],
properties: {
baz: {
type: 'integer',
format: 'uint16',
minimum: 0,
nullable: true
},
qux: {
type: 'integer',
format: 'uint8',
minimum: 0
}
}
} as const;
export const $ParameterSimpleParameterUnused = {
description: 'Model used to test deduplication strategy (unused)',
type: 'string'
Expand Down
Loading

0 comments on commit 0e14810

Please sign in to comment.