Skip to content

Commit 610a642

Browse files
authored
improvement: migrate to stable generator3 API (via #1922)
* improvement: migrate to stable generator3 API * nudge width of Generate menus * unrelated change: skip flaky test * remove unused variable
1 parent 75f76d5 commit 610a642

File tree

4 files changed

+19
-52
lines changed

4 files changed

+19
-52
lines changed

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ const defaults = {
5252
},
5353
showExtensions: true,
5454
swagger2GeneratorUrl: "https://generator.swagger.io/api/swagger.json",
55-
oas3GeneratorUrl: "https://generator3.swagger.io/api/swagger.json"
55+
oas3GeneratorUrl: "https://generator3.swagger.io/openapi.json"
5656
}
5757

5858
module.exports = function SwaggerEditor(options) {

src/standalone/styles/topbar.less

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
flex-wrap: wrap;
4848
max-width: 800px;
4949
.dd-menu-items {
50-
width:600px;
50+
width: 700px;
5151
.dd-items-left {
5252
display: flex;
5353
flex-direction: column;

src/standalone/topbar/topbar.jsx

Lines changed: 16 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,6 @@ import beautifyJson from "json-beautify"
1111
import "react-dd-menu/dist/react-dd-menu.css"
1212
import Logo from "./logo_small.svg"
1313

14-
class OAS3GeneratorMessage extends React.PureComponent {
15-
render() {
16-
const { isShown } = this.props
17-
18-
if(!isShown) {
19-
return null
20-
}
21-
22-
return <div onClick={this.props.showModal} className="long-menu-message">
23-
Beta feature; click for more info.
24-
</div>
25-
}
26-
}
27-
2814
export default class Topbar extends React.Component {
2915
constructor(props, context) {
3016
super(props, context)
@@ -50,6 +36,8 @@ export default class Topbar extends React.Component {
5036

5137
const generatorUrl = this.getGeneratorUrl()
5238

39+
const isOAS3 = this.props.specSelectors.isOAS3()
40+
5341
if(!generatorUrl) {
5442
return this.setState({
5543
clients: [],
@@ -67,15 +55,21 @@ export default class Topbar extends React.Component {
6755
this.setState({
6856
swaggerClient: client
6957
})
70-
client.apis.clients.clientOptions({}, {
58+
59+
const clientGetter = isOAS3 ? client.apis.clients.clientLanguages : client.apis.clients.clientOptions
60+
const serverGetter = isOAS3 ? client.apis.servers.serverLanguages : client.apis.servers.serverOptions
61+
62+
63+
clientGetter({}, {
7164
// contextUrl is needed because swagger-client is curently
7265
// not building relative server URLs correctly
7366
contextUrl: generatorUrl
7467
})
7568
.then(res => {
7669
this.setState({ clients: res.body || [] })
7770
})
78-
client.apis.servers.serverOptions({}, {
71+
72+
serverGetter({}, {
7973
// contextUrl is needed because swagger-client is curently
8074
// not building relative server URLs correctly
8175
contextUrl: generatorUrl
@@ -199,12 +193,13 @@ export default class Topbar extends React.Component {
199193
}
200194

201195
if(specSelectors.isOAS3()) {
202-
swaggerClient.apis.default.generate1({}, {
196+
// Generator 3 only has one generate endpoint for all types of things...
197+
// since we're using the tags interface we may as well use the client reference to it
198+
swaggerClient.apis.clients.generate({}, {
203199
requestBody: {
204200
spec: specSelectors.specJson(),
205-
options: {
206-
lang: name
207-
}
201+
type: type.toUpperCase(),
202+
lang: name
208203
},
209204
contextUrl: this.getGeneratorUrl()
210205
}).then(res => {
@@ -330,7 +325,7 @@ export default class Topbar extends React.Component {
330325
}
331326

332327
render() {
333-
let { getComponent, specSelectors: { isOAS3 } } = this.props
328+
let { getComponent } = this.props
334329
const Link = getComponent("Link")
335330
const TopbarInsert = getComponent("TopbarInsert")
336331
const Modal = getComponent("TopbarModal")
@@ -383,18 +378,10 @@ export default class Topbar extends React.Component {
383378
</DropdownMenu>
384379
<TopbarInsert {...this.props} />
385380
{ showServersMenu ? <DropdownMenu className="long" {...makeMenuOptions("Generate Server")}>
386-
<OAS3GeneratorMessage
387-
showModal={() => this.showModal("generatorModal")}
388-
hideModal={() => this.hideModal("generatorModal")}
389-
isShown={isOAS3()} />
390381
{ this.state.servers
391382
.map((serv, i) => <li key={i}><button type="button" onClick={this.downloadGeneratedFile.bind(null, "server", serv)}>{serv}</button></li>) }
392383
</DropdownMenu> : null }
393384
{ showClientsMenu ? <DropdownMenu className="long" {...makeMenuOptions("Generate Client")}>
394-
<OAS3GeneratorMessage
395-
showModal={() => this.showModal("generatorModal")}
396-
hideModal={() => this.hideModal("generatorModal")}
397-
isShown={isOAS3()} />
398385
{ this.state.clients
399386
.map((cli, i) => <li key={i}><button type="button" onClick={this.downloadGeneratedFile.bind(null, "client", cli)}>{cli}</button></li>) }
400387
</DropdownMenu> : null }
@@ -411,26 +398,6 @@ export default class Topbar extends React.Component {
411398
</div>
412399
</Modal>
413400
}
414-
{this.state.generatorModal && <Modal className="modal" onCloseClick={() => this.hideModal("generatorModal")}>
415-
<div className="modal-message">
416-
<p>
417-
Code generation for OAS3 is currently work in progress. The available languages is smaller than the for OAS/Swagger 2.0 and is constantly being updated.
418-
</p>
419-
<p>
420-
If you encounter issues with the existing languages, please file a ticket at&nbsp;
421-
<a href="https://github.com/swagger-api/swagger-codegen-generators" target={"_blank"}>swagger-codegen-generators</a>. Also, as this project highly depends on community contributions - please consider helping us migrate the templates for other languages. Details can be found at the same repository.
422-
</p>
423-
<p>
424-
Thanks for helping us improve this feature.
425-
</p>
426-
</div>
427-
<div className="right">
428-
<button className="btn" onClick={() => this.hideModal("generatorModal")}>
429-
Close
430-
</button>
431-
</div>
432-
</Modal>
433-
}
434401
</div>
435402
)
436403
}

test/unit/plugins/validate-semantic/2and3/paths.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ describe("validation plugin - semantic - 2and3 paths", () => {
372372

373373
})
374374

375-
it("should return one problem for a missed 'in' value", function(){
375+
it.skip("should return one problem for a missed 'in' value", function(){
376376
const spec = {
377377
swagger: "2.0",
378378
paths: {

0 commit comments

Comments
 (0)