Skip to content

Commit 512d772

Browse files
committed
Stop using jsonSpec in compilation steps
1 parent a31c509 commit 512d772

File tree

9 files changed

+8
-108
lines changed

9 files changed

+8
-108
lines changed

compiler/src/compiler.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import {
2828
import buildJsonSpec, { JsonSpec } from './model/json-spec'
2929
import { ValidationErrors } from './validation-errors'
3030

31-
type StepFunction = (model: Model, restSpec: Map<string, JsonSpec>, errors: ValidationErrors) => Promise<Model>
31+
type StepFunction = (model: Model, errors: ValidationErrors) => Promise<Model>
3232

3333
/**
3434
* The main job of the compiler is to generate the Model and write it on disk.
@@ -62,7 +62,7 @@ export default class Compiler {
6262

6363
async write (): Promise<void> {
6464
for (const step of this.queue) {
65-
this.model = await step(this.model, this.jsonSpec, this.errors)
65+
this.model = await step(this.model, this.errors)
6666
}
6767

6868
const customStringify = stringify.configure(

compiler/src/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import { readFileSync, existsSync, lstatSync } from 'fs'
2121
import { join, resolve } from 'path'
2222
import { argv } from 'zx'
2323
import Compiler from './compiler'
24-
import validateRestSpec from './steps/validate-rest-spec'
2524
import addInfo from './steps/add-info'
2625
import validateModel from './steps/validate-model'
2726
import readDefinitionValidation from './steps/read-definition-validation'
@@ -72,7 +71,6 @@ compiler
7271
.step(addInfo)
7372
.step(addDeprecation)
7473
.step(readDefinitionValidation)
75-
.step(validateRestSpec)
7674
.step(validateModel)
7775
.step(addExamples)
7876
.write()

compiler/src/model/json-spec.ts

Lines changed: 0 additions & 77 deletions
This file was deleted.

compiler/src/steps/add-deprecation.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,11 @@
1818
*/
1919

2020
import * as model from '../model/metamodel'
21-
import { JsonSpec } from '../model/json-spec'
2221

2322
/**
2423
* Populates the `deprecation` field for endpoints from the value of the corresponding request definition.
2524
*/
26-
export default async function addContentType (model: model.Model, jsonSpec: Map<string, JsonSpec>): Promise<model.Model> {
25+
export default async function addContentType (model: model.Model): Promise<model.Model> {
2726
for (const endpoint of model.endpoints) {
2827
if (endpoint.deprecation != null) {
2928
continue

compiler/src/steps/add-examples.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
*/
1919

2020
import * as model from '../model/metamodel'
21-
import { JsonSpec } from '../model/json-spec'
2221
import * as path from 'path'
2322
import * as fs from 'fs'
2423
import * as yaml from 'js-yaml'
@@ -35,9 +34,7 @@ export default class ExamplesProcessor {
3534
}
3635

3736
// Add request and response examples for all the endpoints in the model.
38-
// Note that the 'jsonSpec' is a parameter that is passed to a 'Step'.
39-
// We don't need that parameter for the the 'addExamples' functionality.
40-
async addExamples (model: model.Model, jsonSpec: Map<string, JsonSpec>): Promise<model.Model> {
37+
async addExamples (model: model.Model): Promise<model.Model> {
4138
const requestExamplesProcessor = new RequestExamplesProcessor(model, this.specsFolder)
4239
const responseExamplesProcessor = new ResponseExamplesProcessor(model, this.specsFolder)
4340
for (const endpoint of model.endpoints) {

compiler/src/steps/add-info.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,11 @@
1818
*/
1919

2020
import * as model from '../model/metamodel'
21-
import { JsonSpec } from '../model/json-spec'
2221

2322
/**
2423
* Adds the `_info` field to the JSON model.
2524
*/
26-
export default async function addInfo (model: model.Model, jsonSpec: Map<string, JsonSpec>): Promise<model.Model> {
25+
export default async function addInfo (model: model.Model): Promise<model.Model> {
2726
model._info = {
2827
title: 'Elasticsearch Request & Response Specification',
2928
license: {

compiler/src/steps/read-definition-validation.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,14 @@
1919

2020
import assert from 'assert'
2121
import * as model from '../model/metamodel'
22-
import { JsonSpec } from '../model/json-spec'
2322
import chalk from 'chalk'
2423

2524
/**
2625
* Verifies if "read" version of interface definitions
2726
* contains the same properties of their "write" version.
2827
* Then, it copies every model.Property from write to read but 'required'.
2928
*/
30-
export default async function readDefinitionValidation (model: model.Model, jsonSpec: Map<string, JsonSpec>): Promise<model.Model> {
29+
export default async function readDefinitionValidation (model: model.Model): Promise<model.Model> {
3130
for (const type of model.types) {
3231
if (type.kind !== 'interface') continue
3332
const readBehavior = type.behaviors?.find(behavior => behavior.type.name === 'OverloadOf')

compiler/src/steps/validate-model.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
import * as model from '../model/metamodel'
2121
import { ValidationErrors } from '../validation-errors'
22-
import { JsonSpec } from '../model/json-spec'
2322
import assert from 'assert'
2423
import { TypeName } from '../model/metamodel'
2524

@@ -46,7 +45,7 @@ enum JsonEvent {
4645
* - verify that request parents don't define properties (would they be path/request/body properties?)
4746
* - verify that unions can be distinguished in a JSON stream (otherwise they should be inheritance trees)
4847
*/
49-
export default async function validateModel (apiModel: model.Model, restSpec: Map<string, JsonSpec>, errors: ValidationErrors): Promise<model.Model> {
48+
export default async function validateModel (apiModel: model.Model, errors: ValidationErrors): Promise<model.Model> {
5049
const initialTypeCount = apiModel.types.length
5150

5251
// Returns the fully-qualified name of a type name

output/schema/validation-errors.json

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,5 @@
11
{
2-
"endpointErrors": {
3-
"_internal.update_desired_nodes": {
4-
"request": [
5-
"Request: query parameter 'master_timeout' does not exist in the json spec",
6-
"Request: query parameter 'timeout' does not exist in the json spec"
7-
],
8-
"response": []
9-
},
10-
"capabilities": {
11-
"request": [
12-
"Request: query parameter 'timeout' does not exist in the json spec"
13-
],
14-
"response": []
15-
}
16-
},
2+
"endpointErrors": {},
173
"generalErrors": [
184
"Dangling type '_global.scripts_painless_execute:PainlessExecutionPosition'",
195
"Dangling type '_global.scripts_painless_execute:PainlessScript'",

0 commit comments

Comments
 (0)