8000 fix(api): generation of jsonschema (#4943) · ovh/cds@37cfcd0 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commit 37cfcd0

Browse files
authored
fix(api): generation of jsonschema (#4943)
1 parent 6f1e8ba commit 37cfcd0

File tree

9 files changed

+33
-24
lines changed

9 files changed

+33
-24
lines changed

engine/api/user_schema.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"reflect"
99

1010
"github.com/alecthomas/jsonschema"
11+
"github.com/iancoleman/orderedmap"
1112

1213
"github.com/ovh/cds/engine/api/action"
1314
"github.com/ovh/cds/engine/api/group"
@@ -61,11 +62,11 @@ func (api *API) getUserJSONSchema() service.Handler {
6162
path = fmt.Sprintf("%s/%s", as[i].Group.Name, as[i].Name)
6263
}
6364
s := slug.Convert(path)
64-
sch.Definitions["Step"].Properties[path] = &jsonschema.Type{
65+
sch.Definitions["Step"].Properties.Set(path, &jsonschema.Type{
6566
Version: "http://json-schema.org/draft-04/schema#",
6667
Ref: "#/definitions/" + s,
6768
Description: as[i].Description,
68-
}
69+
})
6970
sch.Definitions["Step"].OneOf = append(sch.Definitions["Step"].OneOf, &jsonschema.Type{
7071
Required: []string{
7172
path,
@@ -74,25 +75,25 @@ func (api *API) getUserJSONSchema() service.Handler {
7475
})
7576

7677
sch.Definitions[s] = &jsonschema.Type{
77-
Properties: map[string]*jsonschema.Type{},
78+
Properties: orderedmap.New(),
7879
AdditionalProperties: sch.Definitions["Step"].AdditionalProperties,
7980
Type: "object",
8081
}
8182
for j := range as[i].Parameters {
8283
p := as[i].Parameters[j]
8384
switch p.Type {
8485
case "number":
85-
sch.Definitions[s].Properties[p.Name] = &jsonschema.Type{
86+
sch.Definitions[s].Properties.Set(p.Name, &jsonschema.Type{
8687
Type: "integer",
87-
}
88+
})
8889
case "boolean":
89-
sch.Definitions[s].Properties[p.Name] = &jsonschema.Type{
90+
sch.Definitions[s].Properties.Set(p.Name, &jsonschema.Type{
9091
Type: "boolean",
91-
}
92+
})
9293
default:
93-
sch.Definitions[s].Properties[p.Name] = &jsonschema.Type{
94+
sch.Definitions[s].Properties.Set(p.Name, &jsonschema.Type{
9495
Type: "string",
95-
}
96+
})
9697
}
9798
}
9899
}

go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ require (
8989
github.com/hashicorp/vault v0.0.0-20170114041158-f1c8b772fdec
9090
github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d // indirect
9191
github.com/hinshun/vt10x v0.0.0-20180809195222-d55458df857c // indirect
92+
github.com/iancoleman/orderedmap v0.0.0-20190318233801-ac98e3ecb4b0
9293
github.com/imdario/mergo v0.0.0-20180119215619-163f41321a19 // indirect
9394
github.com/inconshreveable/go-update v0.0.0-20160112193335-8152e7eb6ccf
9495
github.com/inconshreveable/mousetrap v1.0.0 // indirect
@@ -233,6 +234,8 @@ require (
233234
sigs.k8s.io/yaml v1.1.0 // indirect
234235
)
235236

237+
replace github.com/alecthomas/jsonschema => github.com/sguiheux/jsonschema v0.2.0
238+
236239
replace github.com/go-gorp/gorp => github.com/yesnault/gorp v2.0.1-0.20190906143353-6210446a0d92+incompatible
237240

238241
replace github.com/docker/docker => github.com/docker/engine v0.0.0-20180816081446-320063a2ad06

go.sum

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,8 @@ github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
283283
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
284284
github.com/huandu/xstrings v1.2.0 h1:yPeWdRnmynF7p+lLYz0H2tthW9lqhMJrQV/U7yy4wX0=
285285
github.com/huandu/xstrings v1.2.0/go.mod h1:DvyZB1rfVYsBIigL8HwpZgxHwXozlTgGqn63UyNX5k4=
286+
github.com/iancoleman/orderedmap v0.0.0-20190318233801-ac98e3ecb4b0 h1:i462o439ZjprVSFSZLZxcsoAe592sZB1rci2Z8j4wdk=
287+
github.com/iancoleman/orderedmap v0.0.0-20190318233801-ac98e3ecb4b0/go.mod h1:N0Wam8K1arqPXNWjMo21EXnBPOPp36vB07FNRdD2geA=
286288
github.com/imdario/mergo v0.0.0-20180119215619-163f41321a19 h1:geJOJJZwkYI1yqxWrAMcgrwDvy4P1XyNNgIyN9d6UXc=
287289
github.com/imdario/mergo v0.0.0-20180119215619-163f41321a19/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
288290
github.com/inconshreveable/go-update v0.0.0-20160112193335-8152e7eb6ccf h1:WfD7VjIE6z8dIvMsI4/s+1qr5EL+zoIGev1BQj1eoJ8=
@@ -495,6 +497,9 @@ github.com/sethgrid/pester v0.0.0-20171127025028-760f8913c048 h1:6Men5bEVIDWxw4f
495497
github.com/sethgrid/pester v0.0.0-20171127025028-760f8913c048/go.mod h1:Ad7IjTpvzZO8Fl0vh9AzQ+j/jYZfyp2diGwI8m5q+ns=
496498
github.com/sguiheux/go-coverage v0.0.0-20190710153556-287b082a7197 h1:qu90yDtRE5WEfRT5mn9v0Xz9RaopLguhbPwZKx4dHq8=
497499
github.com/sguiheux/go-coverage v0.0.0-20190710153556-287b082a7197/go.mod h1:0hhKrsUsoT7yvxwNGKa+TSYNA26DNWMqReeZEQq/9FI=
500+
github.com/sguiheux/jsonschema v0.0.0-20200131132618-0ed13897d53d/go.mod h1:/n6+1/DWPltRLWL/VKyUxg6tzsl5kHUCcraimt4vr60=
501+
github.com/sguiheux/jsonschema v0.2.0 h1:hFHEPxudR6sNcsg50/iuJzHT5d3h3KOvtcg2Hrshs2k=
502+
github.com/sguiheux/jsonschema v0.2.0/go.mod h1:/n6+1/DWPltRLWL/VKyUxg6tzsl5kHUCcraimt4vr60=
498503
github.com/shirou/gopsutil v0.0.0-20170406131756-e49a95f3d5f8 h1:05R1OwSk31dkzqf2Jf27n2IOoF9zkK9LcPgPsEm8U7U=
499504
github.com/shirou/gopsutil v0.0.0-20170406131756-e49a95f3d5f8/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
500505
github.com/sirupsen/logrus v1.0.6/go.mod h1:pMByvHTf9Beacp5x1UXfOR9xyW/9antXMhjMPG0dEzc=

sdk/workflow.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ func (w *Workflow) ValidateType() error {
204204
//WorkflowNodeConditions is either an array of WorkflowNodeCondition or a lua script
205205
type WorkflowNodeConditions struct {
206206
PlainConditions []Work 10000 flowNodeCondition `json:"plain,omitempty" yaml:"check,omitempty"`
207-
LuaScript string `json:"lua_script,omitempty" yaml:"script,omitempty"`
207+
LuaScript string `json:"script,omitempty" yaml:"script,omitempty"`
208208
}
209209

210210
// Value returns driver.Value from WorkflowNodeConditions request.

ui/src/app/model/workflow.model.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ export class WorkflowNodeHookConfigValue {
364364

365365
// WorkflowTriggerConditions is either a lua script to check conditions or a set of WorkflowTriggerCondition
366366
export class WorkflowNodeConditions {
367-
lua_script: string;
367+
script: string;
368368
plain: Array<WorkflowNodeCondition>;
369369
}
370370

ui/src/app/shared/conditions/conditions.component.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export class ConditionsComponent extends Table<WorkflowNodeCondition> implements
4242
}
4343
@Input('conditions') set conditions(conditions: WorkflowNodeConditions) {
4444
this._conditions = conditions;
45-
if (this._conditions.lua_script && this._conditions.lua_script !== '') {
45+
if (this._conditions.script && this._conditions.script !== '') {
4646
this.isAdvanced = true;
4747
} else {
4848
this.isAdvanced = false;
@@ -108,7 +108,7 @@ export class ConditionsComponent extends Table<WorkflowNodeCondition> implements
108108
this.conditions.plain = new Array<WorkflowNodeCondition>();
109109
}
110110

111-
this.previousValue = this.conditions.lua_script;
111+
this.previousValue = this.conditions.script;
112112
let condition = this.conditions.plain.find(cc => cc.variable === 'cds.manual');
113113
if (condition) {
114114
condition.value = <any>(condition.value === 'true' || <any>condition.value === true);
@@ -143,7 +143,7 @@ export class ConditionsComponent extends Table<WorkflowNodeCondition> implements
143143
pushChange(event: string, e?: string): void {
144144
if (event !== 'codemirror') {
145145
this.conditionsChange.emit(this.conditions);
146-
this.conditions.lua_script = '';
146+
this.conditions.script = '';
147147
return;
148148
}
149149
if (event === 'codemirror' && e && e !== this.previousValue) {

ui/src/app/shared/conditions/conditions.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<sui-checkbox class="toggle" [(ngModel)]="isAdvanced">{{'workflow_node_condition_advanced' | translate }}
44
</sui-checkbox>
55
</div>
6-
<div class="ui warning message" *ngIf="conditions.plain && conditions.plain.length && conditions.lua_script">
6+
<div class="ui warning message" *ngIf="conditions.plain && conditions.plain.length && conditions.script">
77
<p>
88
{{'workflow_node_condition_warning' | translate}}
99
</p>
@@ -121,7 +121,7 @@ <h4 class="inline">{{'workflow_node_condition_lua_title' | translate}}</h4>
121121
</div>
122122
</div>
123123
</div>
124-
<codemirror [(ngModel)]="conditions.lua_script" (ngModelChange)="pushChange('codemirror', $event)"
124+
<codemirror [(ngModel)]="conditions.script" (ngModelChange)="pushChange('codemirror', $event)"
125125
(change)="changeCodeMirror($event)" [config]="codeMirrorConfig" #textareaCodeMirror>
126126
</codemirror>
127127
</div>

ui/src/app/shared/workflow/wizard/conditions/wizard.conditions.component.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export class WorkflowWizardNodeConditionComponent extends Table<WorkflowNodeCond
4242
if (!this.editableNode.context.conditions.plain) {
4343
this.editableNode.context.conditions.plain = new Array<WorkflowNodeCondition>();
4444
}
45-
this.previousValue = this.editableNode.context.conditions.lua_script;
45+
this.previousValue = this.editableNode.context.conditions.script;
4646
let condition = this.editableNode.context.conditions.plain.find(cc => cc.variable === 'cds.manual');
4747
if (condition) {
4848
condition.value = <any>(condition.value !== 'false');
@@ -63,7 +63,7 @@ export class WorkflowWizardNodeConditionComponent extends Table<WorkflowNodeCond
6363
this.editableHook.conditions.plain = new Array<WorkflowNodeCondition>();
6464
}
6565

66-
this.previousValue = this.editableHook.conditions.lua_script;
66+
this.previousValue = this.editableHook.conditions.script;
6767
let condition = this.editableHook.conditions.plain.find(cc => cc.variable === 'cds.manual');
6868
if (condition) {
6969
condition.value = <any>(condition.value !== 'false');
@@ -147,10 +147,10 @@ export class WorkflowWizardNodeConditionComponent extends Table<WorkflowNodeCond
147147
updateWorkflow(): void {
148148
this.loading = true;
149149
if (this.editableNode != null) {
150-
if (this.editableNode.context.conditions.lua_script && this.editableNode.context.conditions.lua_script !== '') {
150+
if (this.editableNode.context.conditions.script && this.editableNode.context.conditions.script !== '') {
151151
this.editableNode.context.conditions.plain = null;
152152
} else {
153-
this.editableNode.context.conditions.lua_script = '';
153+
this.editableNode.context.conditions.script = '';
154154
let sizeBefore = this.editableNode.context.conditions.plain.length;
155155

156156

@@ -171,10 +171,10 @@ export class WorkflowWizardNodeConditionComponent extends Table<WorkflowNodeCond
171171
}
172172
}
173173
} else if (this.editableHook != null) {
174-
if (this.editableHook.conditions.lua_script && this.editableHook.conditions.lua_script !== '') {
174+
if (this.editableHook.conditions.script && this.editableHook.conditions.script !== '') {
175175
this.editableHook.conditions.plain = null;
176176
} else {
177-
this.editableHook.conditions.lua_script = '';
177+
this.editableHook.conditions.script = '';
178178
let sizeBefore = this.editableHook.conditions.plain.length;
179179

180180

ui/src/app/views/pipeline/show/workflow/pipeline.workflow.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,10 +268,10 @@ export class PipelineWorkflowComponent implements OnInit, OnDestroy {
268268
this.loadingStage = true;
269269
switch (type) {
270270
case 'update':
271-
if (this.selectedStage.conditions.lua_script && this.selectedStage.conditions.lua_script !== '') {
271+
if (this.selectedStage.conditions.script && this.selectedStage.conditions.script !== '') {
272272
this.selectedStage.conditions.plain = null;
273273
} else {
274-
this.selectedStage.conditions.lua_script = '';
274+
this.selectedStage.conditions.script = '';
275275
}
276276
this.store.dispatch(new pipelineActions.UpdatePipelineStage({
277277
projectKey: this.project.key,

0 commit comments

Comments
 (0)
0