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: No support for special char in emum #311

Closed
bibiboss opened this issue Jan 12, 2024 · 6 comments · Fixed by #314
Closed

Bug: No support for special char in emum #311

bibiboss opened this issue Jan 12, 2024 · 6 comments · Fixed by #314
Assignees
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@bibiboss
Copy link

bibiboss commented Jan 12, 2024

Hello!
First, I'm not sure to write correctly the issue, so I appologize for that. I'll try to be reactive if any information is missing.

It seems that the plugin does not support special char. So far I've been using : and ..
Both this char can be used in a urn definition (https://www.rfc-editor.org/rfc/rfc2141).
While some of my messages exchanged through a bus have URNs inside, it seems that currently it is not possible.

asyncapi.yml example

asyncapi: 2.5.0
info:
  title: Some test
  version: '1.0.0'
  description: |
    This document describes a test".

defaultContentType: application/json
channels:
  events/public/example/{testId}:
    description: The topic where tenant modification are published
    parameters:
      testId:
        $ref: '#/components/parameters/testId'
    subscribe:
      operationId: updateTest
      traits:
        - bindings:
            mqtt:
              retain: true
      message:
        $ref: '#/components/messages/test'

components:
  messages:
    test:
      name: test
      title: Testing the test
      summary: Same
      contentType: application/json
      payload:
        $ref: "#/components/schemas/test"


  schemas:
    test:
      type: object
      properties:
        source:
          type: string
          enum:
            - "urn:namespace:valid:namespace.specific"
        data:
          type: object
          properties:
            meaningfulData:
              type: string
              examples:
                - data
            someOtherData:
              type: string
              examples:
                - bob
    uuid:
      type: string
      description: A UUIDv6
      examples:
        - 69ce3aa7-437e-627c-8845-bd5765b15c6b
        - 1c1de518-507c-63d9-93b3-9e6b0e79c96d
        - e383b6f0-f685-6d60-8a89-2c09bc90c138
        - 0250050f-0b2a-6ff5-a1fd-1479e431bbec
        - bd89a2a2-ddf5-65c8-abd5-8165e41f9e12
      pattern: ^[0-9a-f]{8}-[0-9a-f]{4}-6[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$

  parameters:
    testId:
      description: The identifier of a test
      schema:
        type: string
        examples:
          - "toto"
          - "tata"

mvn configuration

          <plugin>
                <groupId>com.sngular</groupId>
                <artifactId>scs-multiapi-maven-plugin</artifactId>
                <version>5.1.0</version>
                <executions>
                    <execution>
                        <id>asyncapi</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>asyncapi-generation</goal>
                        </goals>
                        <configuration>
                            <specFiles>
                                <specFile>
                                    <filePath>${project.basedir}/test/asyncapi.yml</filePath>
                                    <supplier>
                                        <ids>updateTest</ids>
                                        <apiPackage>test.api</apiPackage>
                                        <modelPackage>test.api.model</modelPackage>
                                    </supplier>
                                </specFile>
                            </specFiles>
                            <generatedSourcesFolder>generated-sources</generatedSourcesFolder>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

Result:
Failing compilation
image

cause:
image

Possible result:
The piece of code could be generated like:

@JsonDeserialize(builder = Test.TestBuilder.class)
public class Test {

  @JsonProperty(value ="source")
  private Source source;
  public enum Source {
    URN_NAMESPACE_VALID_NAMESPACE_SPECIFIC("urn:namespace:valid:namespace.specific");
 }
 // more stuff
}

Best regards

Copy link

Thank you for collaborating with the project by giving us feedback! Cheers!

@jemacineiras jemacineiras self-assigned this Jan 15, 2024
@jemacineiras jemacineiras added bug Something isn't working good first issue Good for newcomers gradle Adding this tag to a PR will create a new gradle version on merge labels Jan 15, 2024
@bibiboss
Copy link
Author

Hello @jemacineiras
I saw the tags you put, I use maven. I don't know if that's relevant for the issue.

@jemacineiras jemacineiras removed the gradle Adding this tag to a PR will create a new gradle version on merge label Jan 15, 2024
@jemacineiras
Copy link
Contributor

jemacineiras commented Jan 17, 2024

Hi @bibiboss,
nowadays when we build an Enum type we are using the literals you add in the enum part as Identifiers. So as standard java language some characters are not allow, like ´:´

what will be produced right now is something like

public enum Source {

  urn:namespace:valid:namespace.specific
  
}

The solution here to support that kind of is build something like

public enum Source {

  URN_NAMESPACE_VALID_NAMESPACE_SPECIFIC("urn:namespace:valid:namespace.specific")

  private final String value;

  Source(final String value) {
    this.value = value;
  }
  
  public String getValue() {
    return value;
  }
}

That will work for you?

Cheers

@bibiboss
Copy link
Author

Hello @jemacineiras

Yes :)

I think there is a list of char to check. On the top of my head I'm thinking about all specials char from regional keyboard (é and è for example), and other java-reserved chars.

Cheers

@jemacineiras
Copy link
Contributor

Hi @bibiboss ,

there is a fix in the branch attached to this issue. If you can test it and works for you, then I can merge it.

Cheers

@bibiboss
Copy link
Author

Hello @jemacineiras

It works well!
Outside specials char like é or ñ that are transformed to _, but since they might be refused in many protocols, I guess we can state that is more related to a non-blocking bug (that is basically aestetics 😄 ).

I'm not stuck on this anymore!

Thanks again for quick answer and fix!

@jemacineiras jemacineiras linked a pull request Jan 18, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants