...

Source file src/github.com/google/gnostic-models/jsonschema/generate-base.go

Documentation: github.com/google/gnostic-models/jsonschema

     1  // Copyright 2020 Google LLC. All Rights Reserved.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //    http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  // +build ignore
    16  
    17  package main
    18  
    19  import (
    20  	"encoding/base64"
    21  	"io/ioutil"
    22  	"os"
    23  )
    24  
    25  func check(err error) {
    26  	if err != nil {
    27  		panic(err)
    28  	}
    29  }
    30  
    31  func write(f *os.File, s string) {
    32  	_, err := f.WriteString(s)
    33  	check(err)
    34  }
    35  
    36  func main() {
    37  	f, err := os.Create("base.go")
    38  	check(err)
    39  
    40  	defer f.Close()
    41  
    42  	write(f, `
    43  // THIS FILE IS AUTOMATICALLY GENERATED.
    44  
    45  package jsonschema
    46  
    47  import (
    48  	"encoding/base64"
    49  )
    50  
    51  func baseSchemaBytes() ([]byte, error){
    52  	return base64.StdEncoding.DecodeString(
    53  `)
    54  	write(f, "`")
    55  
    56  	b, err := ioutil.ReadFile("schema.json")
    57  	check(err)
    58  
    59  	s := base64.StdEncoding.EncodeToString(b)
    60  	limit := len(s)
    61  	width := 80
    62  	for i := 0; i < limit; i += width {
    63  		if i > 0 {
    64  			write(f, "\n")
    65  		}
    66  		j := i + width
    67  		if j > limit {
    68  			j = limit
    69  		}
    70  		write(f, s[i:j])
    71  	}
    72  	write(f, "`)}")
    73  }
    74  

View as plain text