-
Notifications
You must be signed in to change notification settings - Fork 38
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
Use OpenAPI definitions as configuration schema #1022
base: main
Are you sure you want to change the base?
Changes from 3 commits
20d68a5
34ae78d
a829017
d99f5fd
f98f862
ab8eb9f
94cd905
069cf87
0c289c3
fcdc80f
c0a3338
c56fdf9
c727e12
2e36183
7da91a8
eb208a4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,11 +4,11 @@ | |
|
||
<div class="form-item__value"> | ||
<div class="input-option__field"> | ||
<select :id="field" v-model="flagValue" class="form-item__input"> | ||
<option v-for="(flagValue, name) in flags" v-show="flagValue === 0 || !((value & flagValue) === flagValue)" :value="flagValue"> | ||
{{ name }} | ||
</option> | ||
<select :id="field" v-model="flagValue" class="form-item__input" :disabled="!availableFlags.length"> | ||
<option v-for="{ label, flag } in availableFlags" :value="flag">{{ label }}</option> | ||
<option :value="null" disabled v-if="!availableFlags.length">{{ $t('input-all-selected') }}</option> | ||
</select> | ||
|
||
<button class="button" @click.prevent="addFlag"> | ||
{{ $t('add') }} | ||
</button> | ||
|
@@ -33,27 +33,46 @@ | |
mixins: [Input], | ||
data() { | ||
return { | ||
flagValue: this.schema.defaultValue | ||
flagValue: null | ||
}; | ||
}, | ||
computed: { | ||
availableFlags() { | ||
return this.flags | ||
.filter(({ flag }) => (flag & this.value) !== flag); | ||
}, | ||
flags() { | ||
return this.schema.values; | ||
return Object.entries(this.schema['x-definition']) | ||
.map(([label, flag]) => ({ | ||
label, | ||
flag | ||
})) | ||
.filter(({ flag }) => flag % 2 === 0 || flag === 1); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure if I understand this code right but example value of Standalone flag is a value which is equal to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great catch, of course I didn't think too much coding this line, it was supposed to check whether the value is single flag ( |
||
} | ||
}, | ||
created () { | ||
this.setDefaultFlag() | ||
}, | ||
methods: { | ||
setDefaultFlag() { | ||
this.flagValue = !this.availableFlags.length ? null : this.availableFlags[0].flag; | ||
}, | ||
addFlag() { | ||
if (!this.flagValue) return; | ||
if (!this.flagValue && this.flagValue !== 0) return; | ||
|
||
if (this.flagValue === 0) this.value = 0; | ||
|
||
this.value |= this.flagValue; | ||
this.flagValue = this.schema.defaultValue; | ||
this.setDefaultFlag(); | ||
}, | ||
removeFlag(value) { | ||
this.value &= ~value; | ||
if (!this.flagValue) this.setDefaultFlag() | ||
}, | ||
resolveFlagName(value) { | ||
return Object.keys(this.flags).find(key => this.flags[key] === value); | ||
const flag = this.flags.find(({ flag }) => flag === value); | ||
if (!flag) return value; | ||
return flag.label; | ||
} | ||
} | ||
}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a good idea to test if it's
enum
first, then if it'senum flags
. I can't guarantee that swagger won't decide to mark some other type withflags
format just because.