Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

readOnly and writeOnly need improved support in generated output #23

Open
karlvr opened this issue Sep 15, 2021 · 0 comments
Open

readOnly and writeOnly need improved support in generated output #23

karlvr opened this issue Sep 15, 2021 · 0 comments

Comments

@karlvr
Copy link
Owner

karlvr commented Sep 15, 2021

Java validation won't work with readOnly and writeOnly properties as they will all get validated every time. We can use javax.validation groups in order to apply our validation rules to explicit groups... see https://www.baeldung.com/javax-validation-groups

If we try to introduce @javax.annotations.Nonnull annotations we will still have issues... maybe solved as for TypeScript

TypeScript has interfaces, and we add readonly annotations to our readOnly properties. However if a readOnly property is required then we need to set it when we make a new object conforming to the interface, but we don't want to, because we're not going to send it!

Maybe we can make some support interfaces and functions to help with this...

export type OptionListItemFieldRequest = Omit<OptionListItemField, 'name' | 'instantApprove' | 'optionLists'>

export function newOptionListItemField(init: OptionListItemFieldRequest): OptionListItemField {
	return {
		name: '',
		instantApprove: false,
		optionLists: [],
		...init,
	}
}

So we get a type (XRequest) that represents everything that isn't readOnly and a function to turn that type into the original so we can use it everywhere.

We then also need the explicit JSON serialisation from https://github.com/karlvr/openapi-generator-plus-express-passport so that we only serialize what we should.

Maybe these sorts of functions would be useful anyway for creating new instances of interfaces that have discriminators, so you don't have to set the discriminator yourself!

karlvr added a commit that referenced this issue Sep 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant