Comments (7)
Sure – I've done as proposed by you.
from java-spring-template.
Welcome to AsyncAPI. Thanks a lot for reporting your first issue. Please check out our contributors guide and the instructions about a basic recommended setup useful for opening a pull request.
Keep in mind there are also other channels you can use to interact with AsyncAPI community. For more details check out this issue.
from java-spring-template.
@patrickp-at-work hey, please try adding the $id
to schemas, to get the names of schemas that you want
from java-spring-template.
Thanks @derberg for your advice. I had never come across the $id
syntax so far (probably because openapi 3.0 doesn't support it). I've tried $id
and found that I can change the name of Pet
...
Pet:
type: object
discriminator: petType
$id: "Patty"
properties:
name:
type: string
petType:
type: string
required:
- name
- petType
... but adding it to an inline schema didn't work, despite trying for quite a while: Either still yielded "anonymous" or classes not being created at all.
Cat:
description: A representation of a cat
$id: "Kitten"
allOf:
- $ref: '#/components/schemas/Pet'
- type: object
properties:
huntingSkill:
type: string
description: The measured skill for hunting
enum:
- clueless
- lazy
- adventurous
- aggressive
required:
- huntingSkill
Do you have a working example? That would be really cool. Thanks in advance
from java-spring-template.
Tbh I prefer the 2nd example from your issue description, kind looks cleaner to me. To get what you want using $id
you would have to do something like:
asyncapi: 2.0.0
info:
title: Pet Service
version: 1.0.0
description: This service is in charge of processing pet updates
channels:
sample/pet/updated/v1:
publish:
operationId: petUpdated
summary: Pet Update
description: Notify about Pet Update that has taken place
message:
$ref: '#/components/messages/PetNotificationMessage'
components:
messages:
PetNotificationMessage:
headers: {}
payload:
$ref: '#/components/schemas/CatSchema'
schemas:
Pet:
type: object
discriminator: petType
properties:
name:
type: string
petType:
type: string
required:
- name
- petType
CatSchema: ## "Cat" will be used as the discriminator value
description: A representation of a cat
allOf:
- $ref: '#/components/schemas/Pet'
- type: object
$id: Cat
properties:
huntingSkill:
type: string
description: The measured skill for hunting
enum:
- clueless
- lazy
- adventurous
- aggressive
required:
- huntingSkill
DogSchema: ## "Dog" will be used as the discriminator value
description: A representation of a dog
$id: Dogs
allOf:
- $ref: '#/components/schemas/Pet'
- type: object
$id: Dog
properties:
packSize:
type: integer
format: int32
description: the size of the pack the dog is from
minimum: 0
required:
- packSize
Nevertheless, the code is not going to be what you expect, petType
property will not be available in Cat and Dog classes.
I think this default behaviour is correct. As I understand you expect that in case of discriminator
usage, it should be supported?
from java-spring-template.
First of all, thanks for the usage example. Secondly, thanks for the hint regarding the meaning of publish
vs. subscribe
in the linked issue.
the code is not going to be what you expect,
petType
property will not be available in Cat and Dog classes
Correct, that's what I would have expected; instead, it generates AllOfPetCat
.
However, it solves the original "main" problem of this issue because there is no AnonymousSchema<X>
any more.
I think this default behaviour is correct. As I understand you expect that in case of discriminator usage, it should be supported?
In fact, I rather think that the specification is unclear about that:
While composition offers model extensibility, it does not imply a hierarchy between the models.
I interpret that as a way of saying "code generators SHOULD NOT express it with inheritance".
There are are two ways to define the value of a discriminator for an inheriting instance.
That implies "When the discriminator is present, code generators MUST establish inheritance".
The spec then differentiates two examples.
- The first one with the naming choice of
ExtendedErrorModel
looks like a perfect fit for composition / aggregation. - The second one with the
Pet
looks (at least to me) like a perfect fit for inheritance.
My assumption about inheritance is also re-enforced by the section that describes the discriminator
:
The discriminator is the schema property name that is used to differentiate between other schema that inherit this schema. [...] When used, the value MUST be the name of this schema or any schema that inherits it.
But the spec doesn't give any hint how inheritance shall be represented, thus leaving room for interpretation (or confusion :) ).
from java-spring-template.
I think the best would be if you could open a separate issue related to discriminator in the AsyncAPI repo https://github.com/asyncapi/spec/issues
I have to admit I do not know much about this subject and better if it is reported in the repo where the spec is so a wider audience can join the discussion and drive some updates in the spec. Best is always if reporter can open a PR but first a discussion in the issue must take place.
I guess that this issue could be closed once you create the one in the spec repo?
from java-spring-template.
Related Issues (20)
- Support for java.math.BigDecimal HOT 4
- type: string, "maxlength: 512" is not reflected to the generated Java code HOT 2
- Missing clientId in application.yml causing an error HOT 8
- JavaBeans format for lists not compliant, causes failures with spring boot 3.0.2 when validation of list is added HOT 3
- Please add a parameter ( jakartaForKafkaValidation? ) to support both javax.validation and jakarta.validation packages HOT 2
- Need for urgent changes in GitHub Actions automation HOT 3
- Updating code for AMQP configuration HOT 3
- AsyncAPI spec v3 support in Java Spring template HOT 5
- Add @Generated annotation to ease configuring tools for static code analysis HOT 2
- Upgrade the code generated to Spring Boot 3 HOT 2
- Invalid Java class generated for free-form Map data type by use of 'additionalProperties' property HOT 6
- Support decimal min and max HOT 5
- AsyncAPI Gernerator skips to generate java code for spec part containing "allOf"-element HOT 5
- Anonymous class with syntax error HOT 4
- Support parameter for channel HOT 13
- Support traits HOT 5
- AmqpConfig.java file has syntax errors HOT 3
- Add support of WebSocket protocol HOT 20
- Add all argument constructor to generated classes and make setters like a builder HOT 4
- Backslashes in pattern are escaped HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from java-spring-template.