micronaut-projects / micronaut-projects/micronaut-openapi

DuplicateRouteException thrown from Micronaut OpenAPI-generated server

Open
#2,827 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status: awaiting validation status: example attached type: bug
Dominant language
Java
Stars
114
Forks
121
Avg merge
2d 17h
Merged PRs (30d)
25

Description

### Expected Behavior

My service should return success responses on all endpoints

### Actual Behaviour

```
$ curl localhost:8080/pets | jq .
{
"_links": {
"self": [
{
"href": "/pets",
"templated": false
}
]
},
"_embedded": {
"errors": [
{
"message": "More than 1 route matched the incoming request. The following routes matched /pets: GET - /pets, GET - /pets"
}
]
},
"message": "Bad Request"
}
```

Note: I also added a "hello world" endpoint that is not generated from the OpenAPI spec and the service responds successfully to requests on that endpoint

```
$ curl localhost:8080/
Hello World%
```

### Steps To Reproduce

1. Follow [this official guide](https://guides.micronaut.io/latest/micronaut-openapi-generator-server.html) to generate micronaut java server code from an openapi spec
2. Implement the `PetsApi` interface with stubbed success responses using Kotlin
3. `./gradlew run`
4. `$ curl localhost:8080/pets`
5. Observe the error message for duplicate routes

The output of (1) and (2) is linked as an example application

### Environment Information

Operating System: OSX Version 13.2.1 (22D68)

JDK Version
```
$ javac --version
javac 17.0.4.1
```

JRE Version
```
$ java --version
openjdk 17.0.4.1 2022-08-12
OpenJDK Runtime Environment Temurin-17.0.4.1+1 (build 17.0.4.1+1)
OpenJDK 64-Bit Server VM Temurin-17.0.4.1+1 (build 17.0.4.1+1, mixed mode)
```

### Example Application

https://github.com/lyonssp/petstore-service

### Version

4.0.2

Contributor guide

No contributing guide indexed for this repository

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 linked petstore-service example and the generated PetsApi implementation described in the reproduction, then trace how the OpenAPI server generator registers the GET /pets route. Reproduce the request with ./gradlew run and curl; done means the generated endpoint has only one matching route and returns its success response.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, kotlin, openapi
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.