swagger-api / swagger-api/swagger-codegen

Incompatible string handling between .NET client and Spring Boot service

Open
#7,694 0 comments 2 reactions 0 assignees View on GitHub

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
  1. Generate .NET and Java code using the above YAML
  2. 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)

  1. 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.