Skip to content

[BUG][SPRING] Incorrect handling of format: byte in query strings #22898

@A18022

Description

@A18022

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

When generating a spring-cloud implementation with a query string parameter with format: byte the parameter is not decoded as base64 (as required by the spec).

openapi-generator version

1.8.0

OpenAPI declaration file content or url
openapi: '3.0.3'
info:
  title: Test API
  version: '1.0'
servers:
  - url: https://api.server.test/v1
paths:
  /test:
    get:
      parameters:
        - name: data
          in: query
          schema:
            type: string
            format: byte
      responses:
        '200':
          description: OK
Generation Details

pom.xml:

<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<executions>
	<execution>
		<id>generate-api</id>
		<goals>
			<goal>generate</goal>
		</goals>
		<configuration>
			<inputSpec>
				${project.basedir}/src/main/resources/testapi.yaml
			</inputSpec>
			<generatorName>spring</generatorName>
			<library>spring-boot</library>
			<generateSupportingFiles>false</generateSupportingFiles>
			<skipOperationExample>true</skipOperationExample>
			<configOptions>
				<delegatePattern>false</delegatePattern>
				<useSpringBoot3>true</useSpringBoot3>
				<interfaceOnly>true</interfaceOnly>
			</configOptions>
		</configuration>
	</execution>
</executions>
</plugin>
Steps to reproduce

Generate code from the spec above. Implement the endpoint:

@RestController
public class TestController implements TestApi {

    @Override
    public ResponseEntity<Void> testGet(byte[] data) {
        StringBuilder hexString = new StringBuilder();
        for (byte b : data) {
            hexString.append(String.format("%02x", b));
        }
        System.out.println(hexString.toString());
        return ResponseEntity.ok().build();
    }
}

Note: The paramter is a byte[] as expected.

Send a sample request:

curl http://localhost:8080/test?data=abc

Actual output: 616263 (ascii encoding of "abc")
Expected output: 69b7 (base64 decoding of "abc")

Related issues/PRs
Suggest a fix

I don't know Spring very well, maybe there is some kind of annotation that can be used to make Spring decode the value correctly? Alternatively the generator should emit an error that format: byte is not supported.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions