jhipster / generator-jhipster

JHipster is a development platform to quickly generate, develop, & deploy modern web applications & microservice architectures.
https://www.jhipster.tech
Apache License 2.0
21.56k stars 4.02k forks source link

OpenAPI subgenerator mapping JHipster entities to openapi schemas/resources #16685

Closed ivangsa closed 2 years ago

ivangsa commented 3 years ago
Overview of the feature request

With JHipster is easy to generate CRUD microservices for a given domain model described as JDL (DDD)

With OpenAPI/Swagger we can describe an API.

If we add some extension tags to OpenAPI definitions mapping schemas to entities then a subgenerator could generate api controller implementation that links repository/services/entities with openapi resources.

Customizing the famous petstore:

Pet:
  required:
  - name
  - photoUrls
  x-jhipster-model: **PetEntity**
  type: object
  properties:
    id:
      type: integer
      format: int64
      example: 10
      **x-jhipster-id: true**
    name:
      type: string
      example: doggie

could generate something like this:

@Service
public class PetApiDelegateImpl implements PetApiDelegate {
    @Autowired
    PetRepository petRepository;
    @Autowired
    PetMapper petMapper;
    @Override
    public ResponseEntity<List<Pet>> findPetsByStatus(List<String> status) {
        return ResponseEntity.ok(
            petMapper.map(petRepository.findAll())
        );
    }
}
Motivation for or Use Case

This is just an idea inspired on this project https://github.com/apiaddicts/apigen (sorry it's in spanish) that generates full backend from an OpenAPI sprinkled with some special x- tags

I think this could be a good addition to the richness of JHipster model based code generation

Related issues or PR
Tcharl commented 3 years ago

What about even drop the jdl generated Resource and replace them by openapi generation? Would slim the framework and ensure best practices (and extensibility) WDYT?

github-actions[bot] commented 2 years ago

This issue is stale because it has been open 30 days with no activity. Our core developers tend to be more verbose on denying. If there is no negative comment, possibly this feature will be accepted. We are accepting PRs :smiley:. Comment or this will be closed in 7 days

CGarces commented 2 years ago

Ouch! was a good idea but I don't have time to help with the implementation.