Commit 0476d3e9 authored by cazenave's avatar cazenave
Browse files

swagger form

parent a581a15f
<p>accessapi works!</p>
<form [formGroup]="Form" (ngSubmit)="swaggertoyaml(buttonType)">
<label>Upload and fill form width repository description file: </label><br>
<input type="file" id="repofile" name="repofile " class="btn btn-primary" (change)="swaggertoyaml('fill')" ><br>
<label>Or describe your repository and save a new file for publishing in the FDP database:</label><br>
<div class="form-group">
<label>title
<input type="text" class="form-control" formControlName="title" required>
</label>
</div>
<div class="form-group">
<label>Description
<textarea class="form-control" formControlName="description"></textarea>
</label>
</div>
<div class="form-group">
<label>version</label>
<input type="text" class="form-control" formControlName="version">
</div>
<div class="form-group">
<label>url</label>
<input type="text" class="form-control" formControlName="url">
</div>
<div class="form-group">
<label>Description
<textarea class="form-control" formControlName="urldescription"></textarea>
</label>
</div>
<div class="form-group">
<label>paths</label>
<input type="text" class="form-control" formControlName="paths">
</div> <div class="form-group">
<label>verb</label>
<input type="text" class="form-control" formControlName="verb">
</div> <div class="form-group">
<label>summary</label>
<input type="text" class="form-control" formControlName="summary">
</div>
<div class="form-group">
<label>description</label>
<textarea class="form-control" formControlName="verbdescription"></textarea>
</div>
<div class="form-group">
<label>responses</label>
<input type="text" class="form-control" formControlName="responses">
</div>
<div class="form-group">
<label>description</label>
<textarea class="form-control" formControlName="responsedescription"></textarea>
</div>
<div class="form-group">
<label>content</label>
<input type="text" class="form-control" formControlName="content">
</div>
<div class="form-group">
<label>schema</label>
<input type="text" class="form-control" formControlName="schema">
</div>
<div class="form-group">
<label>items</label>
<input type="text" class="form-control" formControlName="items">
</div>
<div>
<br>
<button type="submit" (click)="swaggertoyaml('submit')" class="btn btn-primary">Save swagger api description file</button>
</div>
</form>
import { Component, OnInit } from '@angular/core';
import { Validators } from '@angular/forms';
import { FormArray } from '@angular/forms';
import { HttpClient } from '@angular/common/http';
import { FileSaverService } from 'ngx-filesaver';
import { FormControl} from '@angular/forms';
import { FormGroup} from '@angular/forms';
@Component({
selector: 'app-accessapi',
......@@ -7,9 +14,114 @@ import { Component, OnInit } from '@angular/core';
})
export class AccessapiComponent implements OnInit {
constructor() { }
public fileName: string;
public importFile: File;
Form = new FormGroup({
title: new FormControl('', Validators.required),
description: new FormControl(''),
version: new FormControl(''),
url: new FormControl(''),
urldescription: new FormControl(''),
paths: new FormControl(''),
verb: new FormControl(''),
summary: new FormControl(''),
verbdescription: new FormControl(''),
responses: new FormControl(''),
responsedescription: new FormControl(''),
content: new FormControl(''),
schema: new FormControl(''),
items: new FormControl(''),
filetofill: new FormControl(),
});
constructor(
private _httpClient: HttpClient,
private _FileSaverService: FileSaverService,
) { }
ngOnInit() {
}
swaggertoyaml(buttonType) {
if (buttonType == 'submit') {
let data: string;
data ='openapi: 3.0.0 \n\
info: \n\
title: '+ this.Form.value.title +' \n\
description: '+ this.Form.value.description +' \n\
version: '+ this.Form.value.version +' \n\
server: \n\
- url: '+ this.Form.value.url +' \n\
description: '+ this.Form.value.urldescription +' \n\
paths: \n\
'+this.Form.value.paths+': \n\
'+ this.Form.value.verb +': \n\
summary: '+ this.Form.value.summary +' \n\
description: '+ this.Form.value.verbdescription +' \n\
responses: \n\
'+ this.Form.value.responses +': \n\
description: '+ this.Form.value.responsedescription +' \n\
content: \n\
'+ this.Form.value.content +': \n\
schema: \n\
type: '+ this.Form.value.schema +' \n\
items: \n\
type: '+ this.Form.value.items +' \n\
'
const fileName = `swagger.yaml`;
const fileType = this._FileSaverService.genType(fileName);
const txtBlob = new Blob([data], { type: fileType });
this._FileSaverService.save(txtBlob, fileName);
}
if (buttonType == 'fill') {
const files = (event.target as HTMLInputElement).files;
this.importFile = files[0];
let text = "";
let lines = [];
let line = "";
let map = new Map();
let fileReader = new FileReader();
fileReader.onload = (event) => {
text = fileReader.result as string;
lines = text.split("\n");
for ( let i = 0; i < lines.length; i++) {
line = lines[i].split(": ");
map.set(line[0].trim(),line[1]);
}
this.Form.setValue({
title: map.get('title'),
description: map.get('description'),
version: map.get('version'),
url: map.get('- url'),
urldescription: map.get('description'),
paths: '',
verb: '',
summary: map.get('summary'),
verbdescription: map.get('description'),
responses: '',
responsedescription: map.get('description'),
content: '',
schema: map.get('schema'),
items: map.get('items'),
filetofill: ''
});
}
fileReader.readAsText(this.importFile);
}
}
}
......@@ -68,7 +68,7 @@ repository: \n\
let map = new Map();
let fileReader = new FileReader();
fileReader.onload = (event) => {
text = fileReader.result;
text = fileReader.result as string;
lines = text.split("\n");
for ( let i = 0; i < lines.length; i++) {
......@@ -90,7 +90,7 @@ repository: \n\
fileReader.readAsText(this.importFile);
}
}
}
......
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-settingsmartapi',
templateUrl: './settingsmartapi.component.html',
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment