question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Conditional required properties (if/then/else)

See original GitHub issue

Hey,

Loosley related to #288, most likely just a question and not a request 😃 I again have this code:

    @JsonAlias("uid")
    @JsonPropertyDescription("The ID of the parameter. This ID must be unique in a given application.")
    public String id;

    // Compat with 4.x
    @Deprecated(forRemoval = true)
    @JsonProperty("uid")
    @JsonPropertyDescription("DEPRECATED: Use 'id' instead.")
    public String getUid() {
        return id;
    };

Now I would like the schema to require either of them to be set. AFAIK this is achieved using if/then/else in the schema (?) - how would I best go about configuring the generator appropriately? Thanks!

(Note: Both id and uid end up in the schema fine already, thanks to #288 one of them is even marked deprecated)

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
mduftcommented, Oct 3, 2022

Hey. I adapted my code to be very close to what you provided. Thanks. That solves all the remaining issues I had 😃

0reactions
mduftcommented, Sep 30, 2022

Woah, nice, thanks a TON! Will try this on Monday!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Applying Subschemas Conditionally - JSON Schema
dependentRequired¶. The dependentRequired keyword conditionally requires that certain properties must be present if a given property is present in an object ...
Read more >
jsonSchema attribute conditionally required - Stack Overflow
I can think of four different ways to conditionally require a field. Dependencies. The dependentSchemas keyword is a conditional way to apply a...
Read more >
If Then Else - Liquid Technologies
The 3 properties If, Then, Else make it possible to specify conditional validation rules for a schema. Each of them contains a JSON...
Read more >
Applying subschemas conditionally | Opis JSON Schema
if-then-else. This is a conditional structure containing three keywords: if , then and else . Every keyword value must be a valid JSON...
Read more >
Field required based on condition · Issue #539 · json-schema ...
conditional requirement of properties; conditions expressed as relationships among properties. The first part can be implemented today with if :.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found