Skip to content

[BUG] Support for typescript schemaMappings is missing #12802

@hnuttin

Description

@hnuttin

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

When generating typescript-angular api's from a spec that uses externe type mappings inside a response body, the generator is stuck in an infinite loop when trying to 'unalias' the schema for the external type.

Exception in thread "main" java.lang.StackOverflowError at java.util.regex.Pattern.error(Pattern.java:1969) at java.util.regex.Pattern.<init>(Pattern.java:1354) at java.util.regex.Pattern.compile(Pattern.java:1054) at java.lang.String.replace(String.java:2239) at org.openapitools.codegen.utils.ModelUtils.getSimpleRef(ModelUtils.java:406) at org.openapitools.codegen.utils.ModelUtils.unaliasSchema(ModelUtils.java:1208) at org.openapitools.codegen.utils.ModelUtils.unaliasSchema(ModelUtils.java:1256) at org.openapitools.codegen.utils.ModelUtils.unaliasSchema(ModelUtils.java:1256) at org.openapitools.codegen.utils.ModelUtils.unaliasSchema(ModelUtils.java:1256)

openapi-generator version

6.0.1

OpenAPI declaration file content or url
openapi: 3.0.1
info:
  title: OpenAPI definition
  version: v0
paths:
  "/api/external-resources":
    get:
      operationId: getExternalResources
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: array
                items:
                  "$ref": "#/components/schemas/ExternalResource"
components:
  schemas:
    ExternalResource:
      "$ref": "#/components/schemas/ExternalResource"

Generation Details
<plugin>
	<groupId>org.openapitools</groupId>
	<artifactId>openapi-generator-maven-plugin</artifactId>
	<version>6.0.1</version>
	<executions>
		<execution>
			<phase>generate-sources</phase>
			<goals>
				<goal>generate</goal>
			</goals>
			<configuration>
				<inputSpec>openapi.yaml</inputSpec>
				<generatorName>typescript-angular</generatorName>
				<schemaMappings>ExternalResource</schemaMappings>
				<importMappings>ExternalResource=@external/resource</importMappings>
			</configuration>
		</execution>
	</executions>
</plugin>
Steps to reproduce

Generate typescript based on above spec and provided maven plugin configuration.

Related issues/PRs
Suggest a fix

Passing the schemaMapping in AbstractTypeScriptClientCodegen to the unaliasSchema method on lines 433 and 437 fixes the issue.

ModelUtils.unaliasSchema(this.openAPI, items, schemaMapping)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions