mirror of
https://github.com/ferdikoomen/openapi-typescript-codegen.git
synced 2025-12-08 20:16:21 +00:00
- Fixed sorting function
This commit is contained in:
parent
b28173c635
commit
687b678f33
@ -22,7 +22,7 @@ export function getModel(openApi: OpenApi, definition: OpenApiSchema, isDefiniti
|
||||
isDefinition,
|
||||
isReadOnly: definition.readOnly === true,
|
||||
isNullable: definition['x-nullable'] === true,
|
||||
isRequired: definition.default !== undefined,
|
||||
isRequired: false,
|
||||
format: definition.format,
|
||||
maximum: definition.maximum,
|
||||
exclusiveMaximum: definition.exclusiveMaximum,
|
||||
|
||||
@ -15,7 +15,7 @@ export function getModelProperties(openApi: OpenApi, definition: OpenApiSchema,
|
||||
for (const propertyName in definition.properties) {
|
||||
if (definition.properties.hasOwnProperty(propertyName)) {
|
||||
const property = definition.properties[propertyName];
|
||||
const propertyRequired = definition.required?.includes(propertyName) || property.default !== undefined;
|
||||
const propertyRequired = !!definition.required?.includes(propertyName);
|
||||
if (property.$ref) {
|
||||
const model = getType(property.$ref);
|
||||
models.push({
|
||||
|
||||
@ -1,9 +1,23 @@
|
||||
import type { OperationParameter } from '../../../client/interfaces/OperationParameter';
|
||||
|
||||
export function sortByRequired(a: OperationParameter, b: OperationParameter): number {
|
||||
const aNeedsValue = a.isRequired && a.default === undefined;
|
||||
const bNeedsValue = b.isRequired && b.default === undefined;
|
||||
if (aNeedsValue && !bNeedsValue) return -1;
|
||||
if (!aNeedsValue && bNeedsValue) return 1;
|
||||
const aIsRequiredWithoutDefaultValue = a.isRequired && a.default === undefined;
|
||||
const bIsRequiredWithoutDefaultValue = b.isRequired && b.default === undefined;
|
||||
const aIsRequiredWithDefaultValue = a.isRequired && a.default !== undefined;
|
||||
const bIsRequiredWithDefaultValue = b.isRequired && b.default !== undefined;
|
||||
const aIsOptionalWithDefaultValue = !a.isRequired && a.default !== undefined;
|
||||
const bIsOptionalWithDefaultValue = !b.isRequired && b.default !== undefined;
|
||||
const aIsOptionalWithoutDefaultValue = !a.isRequired && a.default === undefined;
|
||||
const bIsOptionalWithoutDefaultValue = !b.isRequired && b.default === undefined;
|
||||
|
||||
if (aIsRequiredWithoutDefaultValue && !bIsRequiredWithoutDefaultValue) return -1;
|
||||
if (bIsRequiredWithoutDefaultValue && !aIsRequiredWithoutDefaultValue) return 1;
|
||||
if (aIsRequiredWithDefaultValue && !bIsRequiredWithDefaultValue) return -1;
|
||||
if (bIsRequiredWithDefaultValue && !aIsRequiredWithDefaultValue) return 1;
|
||||
if (aIsOptionalWithDefaultValue && !bIsOptionalWithDefaultValue) return -1;
|
||||
if (bIsOptionalWithDefaultValue && !aIsOptionalWithDefaultValue) return 1;
|
||||
if (aIsOptionalWithoutDefaultValue && !bIsOptionalWithoutDefaultValue) return -1;
|
||||
if (bIsOptionalWithoutDefaultValue && !aIsOptionalWithoutDefaultValue) return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -23,7 +23,7 @@ export function getModel(openApi: OpenApi, definition: OpenApiSchema, isDefiniti
|
||||
isDefinition,
|
||||
isReadOnly: definition.readOnly === true,
|
||||
isNullable: definition.nullable === true,
|
||||
isRequired: definition.default !== undefined,
|
||||
isRequired: false,
|
||||
format: definition.format,
|
||||
maximum: definition.maximum,
|
||||
exclusiveMaximum: definition.exclusiveMaximum,
|
||||
|
||||
@ -15,7 +15,7 @@ export function getModelProperties(openApi: OpenApi, definition: OpenApiSchema,
|
||||
for (const propertyName in definition.properties) {
|
||||
if (definition.properties.hasOwnProperty(propertyName)) {
|
||||
const property = definition.properties[propertyName];
|
||||
const propertyRequired = definition.required?.includes(propertyName) || property.default !== undefined;
|
||||
const propertyRequired = !!definition.required?.includes(propertyName);
|
||||
if (property.$ref) {
|
||||
const model = getType(property.$ref);
|
||||
models.push({
|
||||
|
||||
@ -1,9 +1,23 @@
|
||||
import type { OperationParameter } from '../../../client/interfaces/OperationParameter';
|
||||
|
||||
export function sortByRequired(a: OperationParameter, b: OperationParameter): number {
|
||||
const aNeedsValue = a.isRequired && a.default === undefined;
|
||||
const bNeedsValue = b.isRequired && b.default === undefined;
|
||||
if (aNeedsValue && !bNeedsValue) return -1;
|
||||
if (!aNeedsValue && bNeedsValue) return 1;
|
||||
const aIsRequiredWithoutDefaultValue = a.isRequired && a.default === undefined;
|
||||
const bIsRequiredWithoutDefaultValue = b.isRequired && b.default === undefined;
|
||||
const aIsRequiredWithDefaultValue = a.isRequired && a.default !== undefined;
|
||||
const bIsRequiredWithDefaultValue = b.isRequired && b.default !== undefined;
|
||||
const aIsOptionalWithDefaultValue = !a.isRequired && a.default !== undefined;
|
||||
const bIsOptionalWithDefaultValue = !b.isRequired && b.default !== undefined;
|
||||
const aIsOptionalWithoutDefaultValue = !a.isRequired && a.default === undefined;
|
||||
const bIsOptionalWithoutDefaultValue = !b.isRequired && b.default === undefined;
|
||||
|
||||
if (aIsRequiredWithoutDefaultValue && !bIsRequiredWithoutDefaultValue) return -1;
|
||||
if (bIsRequiredWithoutDefaultValue && !aIsRequiredWithoutDefaultValue) return 1;
|
||||
if (aIsRequiredWithDefaultValue && !bIsRequiredWithDefaultValue) return -1;
|
||||
if (bIsRequiredWithDefaultValue && !aIsRequiredWithDefaultValue) return 1;
|
||||
if (aIsOptionalWithDefaultValue && !bIsOptionalWithDefaultValue) return -1;
|
||||
if (bIsOptionalWithDefaultValue && !aIsOptionalWithDefaultValue) return 1;
|
||||
if (aIsOptionalWithoutDefaultValue && !bIsOptionalWithoutDefaultValue) return -1;
|
||||
if (bIsOptionalWithoutDefaultValue && !aIsOptionalWithoutDefaultValue) return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -1927,31 +1927,31 @@ export class DefaultsService {
|
||||
|
||||
/**
|
||||
* @param parameterStringWithNoDefault This is a string with no default
|
||||
* @param parameterStringWithDefault This is a string with default
|
||||
* @param parameterStringWithEmptyDefault This is a string with empty default
|
||||
* @param parameterOptionalStringWithDefault This is a optional string with default
|
||||
* @param parameterOptionalStringWithEmptyDefault This is a optional string with empty default
|
||||
* @param parameterOptionalStringWithNoDefault This is a optional string with no default
|
||||
* @param parameterStringWithDefault This is a string with default
|
||||
* @param parameterStringWithEmptyDefault This is a string with empty default
|
||||
* @throws ApiError
|
||||
*/
|
||||
public static async callToTestOrderOfParams(
|
||||
parameterStringWithNoDefault: string,
|
||||
parameterStringWithDefault: string = 'Hello World!',
|
||||
parameterStringWithEmptyDefault: string = '',
|
||||
parameterOptionalStringWithDefault: string = 'Hello World!',
|
||||
parameterOptionalStringWithEmptyDefault: string = '',
|
||||
parameterOptionalStringWithNoDefault?: string,
|
||||
parameterStringWithDefault: string = 'Hello World!',
|
||||
parameterStringWithEmptyDefault: string = '',
|
||||
): Promise<void> {
|
||||
const result = await __request({
|
||||
method: 'PUT',
|
||||
path: \`/api/v\${OpenAPI.VERSION}/defaults\`,
|
||||
query: {
|
||||
'parameterStringWithNoDefault': parameterStringWithNoDefault,
|
||||
'parameterStringWithDefault': parameterStringWithDefault,
|
||||
'parameterStringWithEmptyDefault': parameterStringWithEmptyDefault,
|
||||
'parameterOptionalStringWithDefault': parameterOptionalStringWithDefault,
|
||||
'parameterOptionalStringWithEmptyDefault': parameterOptionalStringWithEmptyDefault,
|
||||
'parameterOptionalStringWithNoDefault': parameterOptionalStringWithNoDefault,
|
||||
'parameterStringWithDefault': parameterStringWithDefault,
|
||||
'parameterStringWithEmptyDefault': parameterStringWithEmptyDefault,
|
||||
},
|
||||
});
|
||||
return result.body;
|
||||
@ -4493,7 +4493,7 @@ export class ComplexService {
|
||||
requestBody?: {
|
||||
readonly key: string | null,
|
||||
name: string | null,
|
||||
enabled: boolean,
|
||||
enabled?: boolean,
|
||||
readonly type: 'Monkey' | 'Horse' | 'Bird',
|
||||
listOfModels?: Array<ModelWithString> | null,
|
||||
listOfStrings?: Array<string> | null,
|
||||
@ -4590,31 +4590,31 @@ export class DefaultsService {
|
||||
|
||||
/**
|
||||
* @param parameterStringWithNoDefault This is a string with no default
|
||||
* @param parameterStringWithDefault This is a string with default
|
||||
* @param parameterStringWithEmptyDefault This is a string with empty default
|
||||
* @param parameterOptionalStringWithDefault This is a optional string with default
|
||||
* @param parameterOptionalStringWithEmptyDefault This is a optional string with empty default
|
||||
* @param parameterOptionalStringWithNoDefault This is a optional string with no default
|
||||
* @param parameterStringWithDefault This is a string with default
|
||||
* @param parameterStringWithEmptyDefault This is a string with empty default
|
||||
* @throws ApiError
|
||||
*/
|
||||
public static async callToTestOrderOfParams(
|
||||
parameterStringWithNoDefault: string,
|
||||
parameterStringWithDefault: string = 'Hello World!',
|
||||
parameterStringWithEmptyDefault: string = '',
|
||||
parameterOptionalStringWithDefault: string = 'Hello World!',
|
||||
parameterOptionalStringWithEmptyDefault: string = '',
|
||||
parameterOptionalStringWithNoDefault?: string,
|
||||
parameterStringWithDefault: string = 'Hello World!',
|
||||
parameterStringWithEmptyDefault: string = '',
|
||||
): Promise<void> {
|
||||
const result = await __request({
|
||||
method: 'PUT',
|
||||
path: \`/api/v\${OpenAPI.VERSION}/defaults\`,
|
||||
query: {
|
||||
'parameterStringWithNoDefault': parameterStringWithNoDefault,
|
||||
'parameterStringWithDefault': parameterStringWithDefault,
|
||||
'parameterStringWithEmptyDefault': parameterStringWithEmptyDefault,
|
||||
'parameterOptionalStringWithDefault': parameterOptionalStringWithDefault,
|
||||
'parameterOptionalStringWithEmptyDefault': parameterOptionalStringWithEmptyDefault,
|
||||
'parameterOptionalStringWithNoDefault': parameterOptionalStringWithNoDefault,
|
||||
'parameterStringWithDefault': parameterStringWithDefault,
|
||||
'parameterStringWithEmptyDefault': parameterStringWithEmptyDefault,
|
||||
},
|
||||
});
|
||||
return result.body;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user