OpenAPITools / OpenAPITools/openapi-generator
importMappings does not work in REF yaml file.
Open
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Description
feature does mot works in referenced documents.
<importMappings>
<importMapping>JavaClass=com.timosh.user.MyClassToReplace</importMapping>
<importMapping>ExternalClass=com.timosh.user.MyClassToReplace</importMapping>
<importMapping>json_myclass=com.timosh.user.MyClassToReplace</importMapping>
</importMappings>
In User.java the Pet has 'Object' type
@JsonProperty("pet")
private Object pet = null;
In Pet.java also Object type
@JsonProperty("javaSimpleClass")
private Object javaSimpleClass = null;
openapi-generator version
Version 5.1.0
OpenAPI declaration file content or url
user.yml
openapi: 3.0.2
info:
title: Test OpenAPI specification
description: "Tutorials on OpenApi"
version: 0.0.1-SNAPSHOT
tags:
- name: user
description: Operations about user
externalDocs:
description: Find out more about our store
url: http://swagger.io
servers:
- url: https://api.phrase.com/v2
paths:
/user/{username}:
get:
tags:
- user
summary: Get user by user name
parameters:
- name: username
in: path
description: 'The name that needs to be fetched. Use user1 for testing. '
required: true
schema:
type: string
responses:
200:
description: successful operation
content:
application/json:
schema:
$ref: '#/components/schemas/User'
404:
description: User not found
content: { }
components:
schemas:
Message:
type: object
required:
- code
- text
properties:
code:
type: integer
text:
type: string
pattern: '^\d{2}-\d{2}$'
Element:
type: object
properties:
text:
type: string
pattern: '^\d{2}-\d{2}$'
User:
type: object
properties:
id:
type: integer
format: int64
username:
type: string
minLength: 4
maxLength: 100
firstName:
type: string
pet:
$ref: './pet.yml#/components/schemas/Pet'
javaClass:
$ref: "#/components/schemas/JavaClass"
javaSimpleClass:
$ref: "#/components/schemas/json_myclass"
my_boolean:
type: boolean
x-codegen-body-parameter-name: boolean_post_body
pet.yml
components:
schemas:
Pet:
type: object
required:
- petName
properties:
id:
type: integer
format: int64
javaSimpleClass:
$ref: "#/components/schemas/JavaClass"
petName:
type: string
nullable: false
minLength: 4
maxLength: 100
Command line used for generation
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>my.timosh.openapi.demo</groupId>
<version>0.1.0</version>
<artifactId>specification-demo</artifactId>
<properties>
<java.version>8</java.version>
<swagger-annotations-version>1.5.22</swagger-annotations-version>
<jackson-version>2.10.2</jackson-version>
<springfox-version>3.0.0</springfox-version>
<spring-boot-starter-test-version>2.1.1.RELEASE</spring-boot-starter-test-version>
<spring-boot-starter-web-version>2.1.0.RELEASE</spring-boot-starter-web-version>
<jackson-databind-nullable>0.2.1</jackson-databind-nullable>
<junit-version>5.7.1</junit-version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>${spring-boot-starter-web-version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${springfox-version}</version>
</dependency>
<dependency>
<groupId>org.openapitools</groupId>
<artifactId>jackson-databind-nullable</artifactId>
<version>${jackson-databind-nullable}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.11</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>${junit-version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit-version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>5.1.0</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/src/main/openapi/openapi.yml</inputSpec>
<generatorName>spring</generatorName>
<skipValidateSpec>true</skipValidateSpec>
<supportingFilesToGenerate>AppUtils.java</supportingFilesToGenerate>
<modelPackage>my.timosh.demo.model</modelPackage>
<generateApis>false</generateApis>
<generateModelTests>false</generateModelTests>
<importMappings>
<importMapping>JavaClass=com.timosh.user.MyClassToReplace</importMapping>
<importMapping>ExternalClass=com.timosh.user.MyClassToReplace</importMapping>
<importMapping>json_myclass=com.timosh.user.MyClassToReplace</importMapping>
</importMappings>
<configOptions>
<java8>true</java8>
<delegatePattern>false</delegatePattern>
<useBeanValidation>true</useBeanValidation>
<performBeanValidation>true</performBeanValidation>
<serializableModel>false</serializableModel>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<proc>none</proc>
</configuration>
</plugin>
</plugins>
</build>
</project>
Steps to reproduce
mvn clean compile
Suggest a fix/enhancement
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the user.yml and pet.yml OpenAPI documents and the Spring generator configuration containing importMappings. Run mvn clean compile to reproduce the generated Java models, then compare the referenced Pet and JavaClass fields with the requested mappings for JavaClass, ExternalClass, and json_myclass. Done means those mappings are applied in referenced documents instead of producing Object fields.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100