swagger-api / swagger-api/swagger-codegen
Incompatible string handling between .NET client and Spring Boot service
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
Using Swagger 2.3.1, I generate code from the below YAML:
- in .NET for the client
- in Spring Boot (Java) for the server
The generated client quotes the string, as the JSON specification requires to, when serializing it to JSON, but the generated server quote fails to remove the quotes when deserializing the string from JSON.
Swagger declaration file content or url
swagger: '2.0'
info:
version: 1.0.0
title: Tedi Server
consumes:
- application/json
produces:
- application/json
paths:
/procedure/server/canClientConnect:
post:
summary: bla bla
operationId: canClientConnect
parameters:
- in: body
name: clientVersionNumber
required: true
schema:
type: string
pattern: '^\d{2}\.\d{2}\.\d{2}(-\S+)?$'
example: 12.02.00-RC.05, oder 14.00.01-SNAPSHOT, oder 13.01.00
responses:
'200':
description: bla bla
schema:
type: string
Command line used for generation
For the client side, on the command line:
java -jar swagger-codegen-cli-2.3.1.jar generate -i tedi.yaml -l csharp
For the server side, in Maven
<plugin>
<groupId>io.swagger</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>2.3.0</version>
<executions>
<execution>
<id>swagger-codegen</id>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/../../tedi-interface/tedi.yaml</inputSpec>
<language>spring</language>
<output>${project.basedir}/generated-sources</output>
<apiPackage>ch.sbb.uno.tedi.api</apiPackage>
<modelPackage>ch.sbb.uno.tedi.model</modelPackage>
<invokerPackage>ch.sbb.uno.tedi.invoker</invokerPackage>
<!-- Some of the following options configure the generated pom.xml. This
would be useful if Maven could process generated modules. But unfortunately
it can't. -->
<configOptions>
<delegatePattern>true</delegatePattern>
<configPackage>ch.sbb.uno.tedi.config</configPackage>
<useTags>true</useTags>
<dateLibrary>java8</dateLibrary>
<!-- The following option does not seem to have any effect. But it shouldn't have any negative one either, I guess. -->
<useBeanValidation>true</useBeanValidation>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
Steps to reproduce
- Generate .NET and Java code using the above YAML
- Call the only POST-endpoint from .NET using 17.08.56 as value for clientVersionNumber
Expected: The service implementation receives String 17.08.56
Actual: The service implementation receives String "17.08.56" (with quotes)
- Have the service implementation return null.
Expected: The client receives null.
Actual The client receives "\0" as a string.
Related issues/PRs
https://github.com/swagger-api/swagger-codegen/issues/1641
looks similar, although not being the exact same problem. It is still open.
Suggest a fix/enhancement
Have the generated code for Spring Boot Json-Encode strings in the body of POST-endpoints like the generated code for .NET does.
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 supplied tedi.yaml and the Spring Boot Maven generation configuration, then inspect the generated POST endpoint for clientVersionNumber. Reproduce the request with the generated .NET client and compare the received string and null response with the expected values. Done means string bodies round-trip without extra quotes and null responses are received as null.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, java, spring-boot
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100