cancel
Showing results for 
Search instead for 
Did you mean: 

Model class name mismatch when using special characters in API name (operationId)

Highlighted
Occasional Visitor

Model class name mismatch when using special characters in API name (operationId)

Say I have an endpoint named: "SEQ-case-investigate-review-results: Review results"

Then when I export this to OpenAPI/Swagger 2.0 (JSON) format, I get the following parameters for this endpoint (along with others):

"operationId": "SEQ-case-investigate-review-results:Reviewresults" and 

"schema": {
"$ref": "#/definitions/SEQ-case-investigate-review-results%3AReviewresultsRequest"
}

You can see that the $ref is url encoded.

I have lots of API with special characters in their name/operationId, which I got from third party.

Due to this, when I'm creating a server stub using SwaggerHub for Java (I've tried JAX-RS and Spring), my model classes are being misnamed in its source code. So if we take the above example, the model class is named "SEQCaseInvestigateReviewResultsReviewresultsRequest". The other classes wanting to use this class are using the name "SEQCaseInvestigateReviewResults3AReviewresultsRequest". SwaggerHub is somehow encoding the name used while "calling" and is not encoding the name for generating the actual model class.

3 REPLIES 3
Highlighted
Staff

Re: Model class name mismatch when using special characters in API name (operationId)

Hello @akash 

 

I was able to reproduce this issue locally, meantime a solution is made i would recommend use the original definition name instead the encoded one, the editor will point that as an error but you can still generates code and get the expected output.

 

So for your case you just need to use:

"schema": {
"$ref": "#/definitions/SEQ-case-investigate-review-results:ReviewresultsRequest"
}

instead:

"schema": {
"$ref": "#/definitions/SEQ-case-investigate-review-results%3AReviewresultsRequest"
}

 

Highlighted
Staff

Re: Model class name mismatch when using special characters in API name (operationId)

btw, where your api document is exported from?

Highlighted
Community Manager

Re: Model class name mismatch when using special characters in API name (operationId)

Thanks a lot hugomario!

 

@akash does the solution work for you?


Sonya Mihaljova
Community and Education Specialist

Learn SmartBear products in a fun and easy way and prove your knowledge!
>>Participate in the TechCorner Challenge today
New Here?
Join us and watch the welcome video:
Top Kudoed Authors