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

Swift5 use json type for any #9206

Merged

Conversation

aymanbagabas
Copy link
Contributor

@aymanbagabas aymanbagabas commented Apr 7, 2021

  • Use a custom JSON type instead of Any

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package 
    ./bin/generate-samples.sh
    ./bin/utils/export_docs_generators.sh
    
    Commit all changed files.
    This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
    These must match the expectations made by your contribution.
    You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*.
    For Windows users, please run the script in Git BASH.
  • File the PR against the correct branch: master, 5.1.x, 6.0.x
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

@aymanbagabas aymanbagabas force-pushed the swift5-use-json-type-for-any branch from 6c02cd5 to 4a3c0b5 Compare April 7, 2021 16:56
@aymanbagabas
Copy link
Contributor Author

@4brunu looks like it's unable to pull one of the dependencies


[ERROR] Failed to execute goal org.apache.maven.plugins:maven-enforcer-plugin:3.0.0-M2:enforce (enforce-maven) on project openapi-generator-project: Execution enforce-maven of goal org.apache.maven.plugins:maven-enforcer-plugin:3.0.0-M2:enforce failed: Plugin org.apache.maven.plugins:maven-enforcer-plugin:3.0.0-M2 or one of its dependencies could not be resolved: Could not transfer artifact org.sonatype.sisu:sisu-guice:jar:noaop:2.1.7 from/to google-maven-central (https://maven-central.storage-download.googleapis.com/maven2/): GET request of: org/sonatype/sisu/sisu-guice/2.1.7/sisu-guice-2.1.7-noaop.jar from google-maven-central failed: Connection reset -> [Help 1]

@4brunu
Copy link
Contributor

4brunu commented Apr 7, 2021

To reset CI, try to close and open the PR.

@aymanbagabas aymanbagabas force-pushed the swift5-use-json-type-for-any branch 3 times, most recently from 0e292af to 6b665eb Compare April 7, 2021 19:18
@aymanbagabas aymanbagabas force-pushed the swift5-use-json-type-for-any branch from 6b665eb to 0eecc43 Compare April 8, 2021 14:48
@aymanbagabas
Copy link
Contributor Author

AnyCodable does not conform to Hashable Flight-School/AnyCodable#45 this is stopping me from switching to AnyCodable

@aymanbagabas
Copy link
Contributor Author

Flight-School/AnyCodable#51 PR submitted and awaiting review

@4brunu
Copy link
Contributor

4brunu commented Apr 8, 2021

You are fast 🙂
By the way I was checking you PR on AnyCodable and both AnyCodable, AnyDecodable and AnyEncodable conform to Equatable.
Maybe also AnyCodable, AnyDecodable and AnyEncodable should conform to Hashable?

@aymanbagabas aymanbagabas force-pushed the swift5-use-json-type-for-any branch from 0eecc43 to 71858ef Compare April 8, 2021 15:19
@aymanbagabas
Copy link
Contributor Author

You are fast 🙂
By the way I was checking you PR on AnyCodable and both AnyCodable, AnyDecodable and AnyEncodable conform to Equatable.
Maybe also AnyCodable, AnyDecodable and AnyEncodable should conform to Hashable?

I updated the PR to conform all to Hashable

@aymanbagabas aymanbagabas force-pushed the swift5-use-json-type-for-any branch 3 times, most recently from 9e19eab to 5a3fe1a Compare April 9, 2021 19:23
@aymanbagabas
Copy link
Contributor Author

I've reverted the mapping change. Just an FYI, swagger codegen swift5 generator also maps binary to Data https://github.com/swagger-api/swagger-codegen-generators/blob/master/src/main/java/io/swagger/codegen/v3/generators/swift/Swift5Codegen.java#L202

@4brunu
Copy link
Contributor

4brunu commented Apr 11, 2021

@aymanbagabas why did you revert the map of binary to Data?
That change looked good to me.

@4brunu
Copy link
Contributor

4brunu commented Apr 11, 2021

Two more thighs:

  • could you please also add the dependency AnyCodable XcodeGen?
  • since we are waiting for the PR you opened on the AnyCodable, and when that PR gets accepted and released, it may create a conflict with the hashable extension on this PR, could you change the AnyCodable dependency to be exactly 0.4.0? Just to try to avoid this future problem

@aymanbagabas aymanbagabas force-pushed the swift5-use-json-type-for-any branch from 5a3fe1a to 679c852 Compare April 12, 2021 14:10
@aymanbagabas
Copy link
Contributor Author

aymanbagabas commented Apr 12, 2021

@4brunu CI is failing even though I updated the test files to reflect the new mapping. Do you know what's going on?

EDIT: I noticed it passes when I also map file to Data.

@4brunu
Copy link
Contributor

4brunu commented Apr 12, 2021

I think you need to update the unit tests in those two places

Assert.assertEquals(property4.dataType, "URL");
Assert.assertEquals(property4.name, "binary");
Assert.assertNull(property4.defaultValue);
Assert.assertEquals(property4.baseType, "URL");

Assert.assertEquals(op.returnType, "URL");
Assert.assertEquals(op.bodyParam.dataType, "URL");

@aymanbagabas
Copy link
Contributor Author

@4brunu
Copy link
Contributor

4brunu commented Apr 12, 2021

I don't have the time to dig unto it now, but maybe it's related to this

} else if (ModelUtils.isBinarySchema(p)) {
property.isBinary = true;
property.isFile = true; // file = binary in OAS3

EDIT: I tried to comment the line property.isFile = true; but it didn't work, so my hint may be wrong

@aymanbagabas
Copy link
Contributor Author

// file = binary in OAS3

Shouldn't we map file to Data?

@4brunu
Copy link
Contributor

4brunu commented Apr 12, 2021

No, let's deal with this problem in a different PR, and we need to investigate more on this issue

@aymanbagabas
Copy link
Contributor Author

No, let's deal with this problem in a different PR, and we need to investigate more on this issue

From reading the OAS3 specs, file data type is not a special type as it's used to be in OAS2, instead, it's treated like any other schema type and is mapped to binary or base64.

@aymanbagabas
Copy link
Contributor Author

aymanbagabas commented Apr 12, 2021

I don't have the time to dig unto it now, but maybe it's related to this

} else if (ModelUtils.isBinarySchema(p)) {
property.isBinary = true;
property.isFile = true; // file = binary in OAS3

EDIT: I tried to comment the line property.isFile = true; but it didn't work, so my hint may be wrong

There is also this

public static boolean isFileSchema(Schema schema) {
if (schema instanceof FileSchema) {
return true;
}
// file type in oas2 mapped to binary in oas3
return isBinarySchema(schema);
}

So essentially file equals to binary. FileSchema is defined as

    public FileSchema() {
        super("string", "binary");
    }

@aymanbagabas aymanbagabas force-pushed the swift5-use-json-type-for-any branch from 679c852 to 1654742 Compare April 21, 2021 18:02
@aymanbagabas aymanbagabas force-pushed the swift5-use-json-type-for-any branch from 1654742 to 68cd30f Compare April 21, 2021 18:05
@aymanbagabas aymanbagabas force-pushed the swift5-use-json-type-for-any branch from 68cd30f to 75b522a Compare April 21, 2021 18:07
@aymanbagabas
Copy link
Contributor Author

I've dropped the mapping commit in favor of #9308

@4brunu
Copy link
Contributor

4brunu commented Apr 21, 2021

Thanks 👍
Looks good to me, let's wait for the CI to finish

@4brunu
Copy link
Contributor

4brunu commented Apr 22, 2021

@wing328 for me this PR is ready to merge

@@ -342,7 +342,15 @@ protected void addAdditionPropertiesToCodeGenModel(CodegenModel codegenModel,
final Schema additionalProperties = getAdditionalProperties(schema);

if (additionalProperties != null) {
codegenModel.additionalPropertiesType = getSchemaType(additionalProperties);
Schema inner = null;
if (ModelUtils.isArraySchema(schema)) {
Copy link
Contributor

@4brunu 4brunu Apr 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aymanbagabas could you please explain what this change does? (the code block, not the line itself)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was getting the wrong inner type for additionalProperties when the schema is either an array or a map.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for explaining the change 🙂

@wing328 wing328 added this to the 5.1.1 milestone Apr 26, 2021
@wing328 wing328 merged commit f7c3773 into OpenAPITools:master Apr 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants