...

Source file src/cuelang.org/go/cue/build/file.go

Documentation: cuelang.org/go/cue/build

     1  // Copyright 2020 CUE Authors
     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  package build
    16  
    17  import "cuelang.org/go/cue/errors"
    18  
    19  // A File represents a file that is part of the build process.
    20  type File struct {
    21  	Filename string `json:"filename"`
    22  
    23  	Encoding       Encoding          `json:"encoding,omitempty"`
    24  	Interpretation Interpretation    `json:"interpretation,omitempty"`
    25  	Form           Form              `json:"form,omitempty"`
    26  	Tags           map[string]string `json:"tags,omitempty"` // code=go
    27  
    28  	ExcludeReason errors.Error `json:"-"`
    29  	Source        interface{}  `json:"-"` // TODO: swap out with concrete type.
    30  }
    31  
    32  // A Encoding indicates a file format for representing a program.
    33  type Encoding string
    34  
    35  const (
    36  	CUE         Encoding = "cue"
    37  	JSON        Encoding = "json"
    38  	YAML        Encoding = "yaml"
    39  	JSONL       Encoding = "jsonl"
    40  	Text        Encoding = "text"
    41  	Binary      Encoding = "binary"
    42  	Protobuf    Encoding = "proto"
    43  	TextProto   Encoding = "textproto"
    44  	BinaryProto Encoding = "pb"
    45  
    46  	// TODO:
    47  	// TOML
    48  
    49  	Code Encoding = "code" // Programming languages
    50  )
    51  
    52  // An Interpretation determines how a certain program should be interpreted.
    53  // For instance, data may be interpreted as describing a schema, which itself
    54  // can be converted to a CUE schema.
    55  type Interpretation string
    56  
    57  const (
    58  	// Auto interprets the underlying data file as data, JSON Schema or OpenAPI,
    59  	// depending on the existence of certain marker fields.
    60  	//
    61  	// JSON Schema is identified by a top-level "$schema" field with a URL
    62  	// of the form "https?://json-schema.org/.*schema#?".
    63  	//
    64  	// OpenAPI is identified by the existence of a top-level field "openapi"
    65  	// with a major semantic version of 3, as well as the existence of
    66  	// the info.title and info.version fields.
    67  	//
    68  	// In all other cases, the underlying data is interpreted as is.
    69  	Auto         Interpretation = "auto"
    70  	JSONSchema   Interpretation = "jsonschema"
    71  	OpenAPI      Interpretation = "openapi"
    72  	ProtobufJSON Interpretation = "pb"
    73  )
    74  
    75  // A Form specifies the form in which a program should be represented.
    76  type Form string
    77  
    78  const (
    79  	Full   Form = "full"
    80  	Schema Form = "schema"
    81  	Struct Form = "struct"
    82  	Final  Form = "final" // picking default values, may be non-concrete
    83  	Graph  Form = "graph" // Data only, but allow references
    84  	DAG    Form = "dag"   // Like graph, but don't allow cycles
    85  	Data   Form = "data"  // always final
    86  )
    87  

View as plain text