Skip to content

Commit

Permalink
fix linting
Browse files Browse the repository at this point in the history
  • Loading branch information
barduinor committed Jan 21, 2025
1 parent 949e91b commit 945d525
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 12 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"pretest": "yarn lint",
"test": "jest",
"lint": "standard --env jest",
"lint_fix": "standard --fix --env jest",
"//": "------------------------------",
"convertAdvanced": "node -e 'require(\"./src/scripts/convertAdvanced.js\").convert()'",
"releaseAdvanced": "node -e 'require(\"./src/scripts/releaseAdvanced.js\").release()'"
Expand Down
8 changes: 4 additions & 4 deletions src/Example.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
class Example {
constructor(schema, openapi) {
constructor (schema, openapi) {
this.openapi = openapi
this.sample = this.value(schema)
}

stringify() {
stringify () {
return JSON.stringify(this.sample, null, 2)
}

// private

generate(props) {
generate (props) {
const output = {}
Object.entries(props).forEach(([key, prop]) => {
output[key] = this.value(prop)
})
return output
}

value(prop) {
value (prop) {
if (prop.example !== undefined) {
return prop.example
} else if (prop.properties && prop.type !== 'string') {
Expand Down
12 changes: 6 additions & 6 deletions src/OpenAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ const { Resolver } = require('@stoplight/json-ref-resolver')
const { JSONPath } = require('jsonpath-plus')

class OpenAPI {
constructor(files, locale) {
constructor (files, locale) {
this.files = files
// this.filename = filename
this.openapi = null
this.locale = locale
this.tags = {}
}

async process() {
async process () {
this.readOpenAPI()
this.openapi = await this.resolveReferences(this.openapi)
this.openapi = this.resolveAllOf(this.openapi)
Expand All @@ -31,7 +31,7 @@ class OpenAPI {

// private

readOpenAPI() {
readOpenAPI () {
// for each file in this.files, read the file, parse it, adn append it to the this.openapi object
for (const file of this.files) {
const source = fs.readFileSync(file).toString()
Expand All @@ -43,7 +43,7 @@ class OpenAPI {
// this.openapi = JSON.parse(source)
}

writeOpenAPI(path) {
writeOpenAPI (path) {
fs.writeFileSync(
path,
JSON.stringify(this.openapi, null, 2)
Expand All @@ -53,7 +53,7 @@ class OpenAPI {
/**
* Resolves all references in a specification
*/
async resolveReferences(specification) {
async resolveReferences (specification) {
const references = await new Resolver().resolve(specification).then(res => res.result)
// make the object writable again, as somehow the resolved returns a write only object
return JSON.parse(JSON.stringify(references))
Expand All @@ -62,7 +62,7 @@ class OpenAPI {
/**
* deepmerges all allOf objects
*/
resolveAllOf(openapi) {
resolveAllOf (openapi) {
const paths = new JSONPath({
path: '$..allOf',
json: openapi,
Expand Down
3 changes: 2 additions & 1 deletion src/scripts/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const OpenAPI = require('../OpenAPI')
const Path = require('../Path')
const Writer = require('../Writer')
const Collection = require('../Collection')
const fs = require('fs')

// const OPENAPI_FILENAME = 'openapi.json'
const OPENAPI_TYPE = 'OAS3'
Expand All @@ -17,7 +18,7 @@ const convert = async (locale = process.argv[1]) => {
path.translate()

// take the above path and scan for files
files = fs.readdirSync(path.folder)
let files = fs.readdirSync(path.folder)
// for each file, include the path and the file name, but only for .json files
files = files.filter(file => file.endsWith('.json')).map(file => `${path.folder}${file}`)
// const filename = `${path.folder}/${OPENAPI_FILENAME}`
Expand Down
3 changes: 2 additions & 1 deletion src/scripts/convertAdvanced.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const OpenAPI = require('../OpenAPI')
const Path = require('../Path')
const Writer = require('../Writer')
const Collection = require('../CollectionAdvanced')
const fs = require('fs')

// const OPENAPI_FILENAME = 'openapi.json'
const OPENAPI_TYPE = 'OAS3'
Expand All @@ -17,7 +18,7 @@ const convert = async (locale = process.argv[1]) => {
path.translate()

// take the above path and scan for files
files = fs.readdirSync(path.folder)
let files = fs.readdirSync(path.folder)
// for each file, include the path and the file name, but only for .json files
files = files.filter(file => file.endsWith('.json')).map(file => `${path.folder}${file}`)
// const filename = `${path.folder}/${OPENAPI_FILENAME}`
Expand Down

0 comments on commit 945d525

Please sign in to comment.