@mittwald/api-code-generator 4.136.1 → 4.199.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,7 @@
1
1
  import { JSONSchema } from "../global/JSONSchema.js";
2
2
  import { Name } from "../global/Name.js";
3
3
  import { asyncStringJoin } from "../../asyncStringJoin.js";
4
+ import { populateNullableTypes } from "../../populateNullableTypes.js";
4
5
  export class Schemas {
5
6
  static ns = "Schemas";
6
7
  schemas;
@@ -9,7 +10,9 @@ export class Schemas {
9
10
  constructor(components, schemas) {
10
11
  this.components = components;
11
12
  this.name = new Name(Schemas.ns, components.name);
12
- this.schemas = Object.entries(schemas ?? {}).map(([schemaName, schema]) => new JSONSchema(new Name(schemaName, this.name), schema));
13
+ this.schemas = Object.entries(schemas ?? {}).map(([schemaName, schema]) => {
14
+ return new JSONSchema(new Name(schemaName, this.name), populateNullableTypes(schema));
15
+ });
13
16
  }
14
17
  async compileTypes(opts) {
15
18
  const t = {
@@ -6,16 +6,17 @@ export class SecurityScheme {
6
6
  jsonSchema;
7
7
  constructor(schemes, name, doc) {
8
8
  this.name = new Name(name, schemes.name);
9
- this.in = doc.in;
9
+ this.in = doc.type === "http" ? "header" : doc.in;
10
+ const propName = doc.type === "http" ? "Authorization" : doc.name;
10
11
  this.jsonSchema = new JSONSchema(this.name, {
11
12
  type: "object",
12
13
  description: doc.description,
13
14
  properties: {
14
- [doc.name]: {
15
+ [propName]: {
15
16
  type: "string",
16
17
  },
17
18
  },
18
- required: [doc.name],
19
+ required: [propName],
19
20
  });
20
21
  }
21
22
  }
@@ -0,0 +1,26 @@
1
+ export function populateNullableTypes(schema) {
2
+ if (!schema || "$ref" in schema) {
3
+ return schema;
4
+ }
5
+ if (schema.properties) {
6
+ for (const key in schema.properties) {
7
+ schema.properties[key] = populateNullableTypes(schema.properties[key]);
8
+ }
9
+ }
10
+ if ("items" in schema && schema.items) {
11
+ schema.items = populateNullableTypes(schema.items);
12
+ }
13
+ const compositionKeys = ["allOf", "anyOf", "oneOf"];
14
+ compositionKeys.forEach((key) => {
15
+ const entries = schema[key];
16
+ if (Array.isArray(entries)) {
17
+ schema[key] = entries.map(populateNullableTypes);
18
+ }
19
+ });
20
+ if (schema.nullable) {
21
+ return {
22
+ anyOf: [schema, { type: "null" }],
23
+ };
24
+ }
25
+ return schema;
26
+ }
@@ -2,9 +2,10 @@ import { OpenAPIV3 } from "openapi-types";
2
2
  import { Name } from "../global/Name.js";
3
3
  import { SecuritySchemes } from "./SecuritySchemes.js";
4
4
  import { JSONSchema } from "../global/JSONSchema.js";
5
+ export type SecuritySchemeType = OpenAPIV3.ApiKeySecurityScheme | OpenAPIV3.HttpSecurityScheme;
5
6
  export declare class SecurityScheme {
6
7
  readonly in: string;
7
8
  readonly name: Name;
8
9
  readonly jsonSchema: JSONSchema;
9
- constructor(schemes: SecuritySchemes, name: string, doc: OpenAPIV3.ApiKeySecurityScheme);
10
+ constructor(schemes: SecuritySchemes, name: string, doc: SecuritySchemeType);
10
11
  }
@@ -0,0 +1,2 @@
1
+ import { OpenAPIV3 } from "openapi-types";
2
+ export declare function populateNullableTypes(schema: OpenAPIV3.ReferenceObject | OpenAPIV3.SchemaObject): OpenAPIV3.ReferenceObject | OpenAPIV3.SchemaObject;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mittwald/api-code-generator",
3
- "version": "4.136.1",
3
+ "version": "4.199.1",
4
4
  "type": "module",
5
5
  "repository": "https://github.com/mittwald/api-client-js.git",
6
6
  "license": "MIT",
@@ -84,5 +84,5 @@
84
84
  "@oclif/plugin-plugins"
85
85
  ]
86
86
  },
87
- "gitHead": "37f84150b556ddbdaa705b6ff1969c4e7fef3d52"
87
+ "gitHead": "2f8c39cf188e9b866a48003394ef2d0fe77d250f"
88
88
  }