Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Type problem if using OpenApi 3.1 (object instead String, Integer etc) #15203

Closed
5 of 6 tasks
SashaVolushkova opened this issue Apr 12, 2023 · 3 comments
Closed
5 of 6 tasks

Comments

@SashaVolushkova
Copy link

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

If you use Openapi 3.1 generator ignors filed types. Just put Object type everywhere.

openapi-generator version

Tested on 6.3.0 - 6.5.0

OpenAPI declaration file content or url

https://github.com/OAI/OpenAPI-Specification/blob/main/examples/v3.1/webhook-example.yaml

Generation Details

Ignors value types in schemes. Just generates models classes with Object type params instead String, Integer etc

Steps to reproduce
plugins {
//...	
id "org.openapi.generator" version "6.5.0"
//....
}

.....
openApiGenerate {
	generatorName = "spring"
	outputDir = "${buildDir}/openapiDir/generated".toString()
	inputSpec = "C:/ideaProjects/!swagger4kafka/ApiFirstServer-main/openapiDir/petstore.yaml"
	globalProperties = [
			apis: "",
			models: "",
			supportingFiles: 'ApiUtil.java'
	]
	apiPackage = "com.volushkova.apifirst.generated"
	modelPackage = "com.volushkova.apifirst.generated.model"
	skipOverwrite = true
	configOptions = [
			dateLibrary: "java8",
			interfaceOnly: "true",
			skipDefaultInterface: "false",
			openApiNullable: "false",
			generateSupportingFiles: "true"
	]
}
  • run openApiGenerate phase
  • go to generated models and you will see:
@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", date = "2023-04-12T16:48:51.346387900+03:00[Europe/Moscow]")
public class Pet {

  private Object id = null;

  private Object name = null;

  private Object tag = null;

  /**
   * Default constructor
   * @deprecated Use {@link Pet#Pet(Object, Object)}
   */
  @Deprecated
  public Pet() {
    super();
  }

  /**
   * Constructor with only required parameters
   */
  public Pet(Object id, Object name) {
    this.id = id;
    this.name = name;
  }

  public Pet id(Object id) {
    this.id = id;
    return this;
  }

  /**
   * Get id
   * @return id
  */
  @NotNull 
  @Schema(name = "id", requiredMode = Schema.RequiredMode.REQUIRED)
  @JsonProperty("id")
  public Object getId() {
    return id;
  }

  public void setId(Object id) {
    this.id = id;
  }

  public Pet name(Object name) {
    this.name = name;
    return this;
  }

  /**
   * Get name
   * @return name
  */
  @NotNull 
  @Schema(name = "name", requiredMode = Schema.RequiredMode.REQUIRED)
  @JsonProperty("name")
  public Object getName() {
    return name;
  }

  public void setName(Object name) {
    this.name = name;
  }

  public Pet tag(Object tag) {
    this.tag = tag;
    return this;
  }

  /**
   * Get tag
   * @return tag
  */
  
  @Schema(name = "tag", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
  @JsonProperty("tag")
  public Object getTag() {
    return tag;
  }

  public void setTag(Object tag) {
    this.tag = tag;
  }
//......
}
  • expexted result - generator will use type from spec-yaml file (String , integer, Long etc).
Related issues/PRs

Not found

Suggest a fix

expexted result - generator will use type from spec-yaml file (String , integer, Long etc).

@SashaVolushkova SashaVolushkova changed the title [BUG] Type problem (object instead String, Integer etc) [BUG] Type problem if using OpenApi 3.1 (object instead String, Integer etc) Apr 12, 2023
@martin-mfg
Copy link
Contributor

Hi,
the problem here is that OpenAPI 3.1.0 is not fully supported yet by OpenAPI generator. When invoking the openApiGenerate phase, the following message is printed as part of the output:

Generation using 3.1.0 specs is in development and is not officially supported yet. If you would like to expedite development, please consider woking on the open issues in the 3.1.0 project: https://github.com/orgs/OpenAPITools/projects/4/views/1 and reach out to our team on Slack at https://join.slack.com/t/openapi-generator/shared_invite/zt-12jxxd7p2-XUeQM~4pzsU9x~eGLQqX2g

This ticket could be considered a sub-task or duplicate of #9083.

For the time being, a helpful workaround could be to use a 3.0.1 OpenAPI spec instead.

Hope this helps!

@wing328
Copy link
Member

wing328 commented Jul 24, 2024

looks like it's fixed in the latest master/stable version.

import org.openapitools.client.JSON;

/**
 * Pet
 */
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = "2024-07-24T19:41:50.516232800+08:00[Asia/Hong_Kong]", comments = "Generator version: 7.8.0-SNAPSHOT")
public class Pet {
  public static final String SERIALIZED_NAME_ID = "id";
  @SerializedName(SERIALIZED_NAME_ID)
  private Long id;

  public static final String SERIALIZED_NAME_NAME = "name";
  @SerializedName(SERIALIZED_NAME_NAME)
  private String name;

  public static final String SERIALIZED_NAME_TAG = "tag";
  @SerializedName(SERIALIZED_NAME_TAG)
  private String tag;


please give it another try with the latest master/stable version when you've time.

@wing328 wing328 closed this as completed Jul 24, 2024
@wing328
Copy link
Member

wing328 commented Jul 24, 2024

fyi @trohovsky-mhp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants